<?php defined('APP_PATH') OR define('APP_PATH','index/');defined('HDPHP_VERSION') OR define('HDPHP_VERSION','2013.12.18');defined('HDPHP_PATH') OR define('HDPHP_PATH','D:/wamp/www/v5/hdphp/hdphp/');defined('ROOT_PATH') OR define('ROOT_PATH','D:/wamp/www/v5/');defined('DEBUG') OR define('DEBUG','');defined('APP_NAME') OR define('APP_NAME','v5');defined('IS_GROUP') OR define('IS_GROUP','');defined('TEMP_PATH') OR define('TEMP_PATH','index/Temp/');defined('TEMP_FILE') OR define('TEMP_FILE','Boot.php');defined('DS') OR define('DS','\\');defined('IS_WIN') OR define('IS_WIN','\\');defined('HDPHP_DATA_PATH') OR define('HDPHP_DATA_PATH','D:/wamp/www/v5/hdphp/hdphp/Data/');defined('HDPHP_LIB_PATH') OR define('HDPHP_LIB_PATH','D:/wamp/www/v5/hdphp/hdphp/Lib/');defined('HDPHP_CONFIG_PATH') OR define('HDPHP_CONFIG_PATH','D:/wamp/www/v5/hdphp/hdphp/Config/');defined('HDPHP_CORE_PATH') OR define('HDPHP_CORE_PATH','D:/wamp/www/v5/hdphp/hdphp/Lib/Core/');defined('HDPHP_EXTEND_PATH') OR define('HDPHP_EXTEND_PATH','D:/wamp/www/v5/hdphp/hdphp/Extend/');defined('HDPHP_ORG_PATH') OR define('HDPHP_ORG_PATH','D:/wamp/www/v5/hdphp/hdphp/Extend/Org/');defined('HDPHP_DRIVER_PATH') OR define('HDPHP_DRIVER_PATH','D:/wamp/www/v5/hdphp/hdphp/Lib/Driver/');defined('HDPHP_EVENT_PATH') OR define('HDPHP_EVENT_PATH','D:/wamp/www/v5/hdphp/hdphp/Lib/Event/');defined('HDPHP_FUNCTION_PATH') OR define('HDPHP_FUNCTION_PATH','D:/wamp/www/v5/hdphp/hdphp/Lib/Function/');defined('HDPHP_LANGUAGE_PATH') OR define('HDPHP_LANGUAGE_PATH','D:/wamp/www/v5/hdphp/hdphp/Lib/Language/');defined('HDPHP_TPL_PATH') OR define('HDPHP_TPL_PATH','D:/wamp/www/v5/hdphp/hdphp/Lib/Tpl/');defined('COMMON_PATH') OR define('COMMON_PATH','index/');defined('COMMON_CONFIG_PATH') OR define('COMMON_CONFIG_PATH','index/');defined('COMMON_MODEL_PATH') OR define('COMMON_MODEL_PATH','index/');defined('COMMON_CONTROL_PATH') OR define('COMMON_CONTROL_PATH','index/');defined('COMMON_LANGUAGE_PATH') OR define('COMMON_LANGUAGE_PATH','index/');defined('COMMON_EXTEND_PATH') OR define('COMMON_EXTEND_PATH','index/');defined('COMMON_EVENT_PATH') OR define('COMMON_EVENT_PATH','index/');defined('COMMON_TAG_PATH') OR define('COMMON_TAG_PATH','index/');defined('COMMON_LIB_PATH') OR define('COMMON_LIB_PATH','index/');final class App { public static function run() { self::loadEventClass(); event("APP_START"); DEBUG and Debug::start("APP_START"); self::init(); self::start(); DEBUG and Debug::show("APP_START", "APP_END"); Log::save(); event("APP_END"); } static private function loadEventClass() { $app_end_event = C("app_event.app_end"); if ($app_end_event) { foreach ($app_end_event as $c) { HDPHP::autoload($c . 'Event'); } } $content_end_event = C("app_event.control_end"); if ($content_end_event) { foreach ($content_end_event as $c) { HDPHP::autoload($c . 'Event'); } } } static private function start() { $control = control(CONTROL); if (!$control) { $control = Control("Empty"); if (!$control) { _404('模块' . CONTROL . '不存在'); } } try { $method = new ReflectionMethod($control, METHOD); if ($method->isPublic()) { $method->invoke($control); } else { throw new ReflectionException; } } catch (ReflectionException $e) { $method = new ReflectionMethod($control, '__call'); $method->invokeArgs($control, array(METHOD, '')); } } private static function init() { define("CHARSET", preg_match('@utf8@i', C("CHARSET")) ? "UTF-8" : C("CHARSET")); define("CHARSET_DB", str_replace("-", "", C("CHARSET"))); date_default_timezone_set(C("default_time_zone")); } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); abstract class Control { private $view = null; protected $options = array(); public function __construct() { event("CONTROL_START", $this->options); if (method_exists($this, "__init")) { $this->__init(); } if (method_exists($this, "__auto")) { $this->__auto(); } } public function __call($method, $args) { if (strcasecmp($method, METHOD) == 0) { if (alias_import($method)) { include alias_import($method); } elseif (method_exists($this, "__empty")) { $this->__empty($args); } else { _404("控制器中不存在方法" . $method); } } else if (substr(ucfirst($method), -5) == "Model") { if (strstr($method, '_')) { $method = str_replace("_", "/", substr($method, 0, -5)); return $this->kmodel($method); } else { return $this->kmodel(substr($method, 0, -5)); } } else { switch (strtolower($method)) { case 'ispost' : case 'isget' : case 'ishead' : case 'isdelete' : case 'isput' : return strtolower($_SERVER['REQUEST_METHOD']) == strtolower(substr($method, 2)); case '_get' : $data = & $_GET; break; case '_post' : $data = & $_POST; break; case '_request' : $data = & $_REQUEST; break; case '_files' : $data = & $_FILES; break; case '_session' : $data = & $_SESSION; break; case '_cookie' : $data = & $_COOKIE; break; case '_server' : $data = & $_SERVER; break; case '_globals' : $data = & $GLOBALS; break; default: throw_exception($method . '方法不存在'); } if (!isset($args[0])) { return $data; } else if (isset($data[$args[0]])) { $value = $data[$args[0]]; if (count($args) > 1 && empty($args[1])) { return $value; } $funcArr = isset($args[1]) && !empty($args[1]) ? $args[1] : C("FILTER_FUNCTION"); if (!empty($funcArr)) { if (!is_array($funcArr)) { $funcArr = explode(",", $funcArr); } foreach ($funcArr as $func) { if (!function_exists($func)) continue; $value = is_array($value) ? array_map($func, $value) : $func($value); } $data[$args[0]] = $value; return $value; } return $value; } else { return isset($args[2]) ? $args[2] : NULL; } } } protected function model($tableName = null, $full = null) { return M($tableName, $full); } protected function kmodel($model) { return K($model); } private function getViewObj() { if (is_null($this->view)) { $this->view = ViewFactory::factory(); } } protected function display($tplFile = null, $cacheTime = null, $cachePath = null, $stat = false, $contentType = "text/html", $charset = "", $show = true) { $this->getViewObj(); return $this->view->display($tplFile, $cacheTime, $cachePath = null, $contentType, $charset, $show); } protected function fetch($tplFile = null, $cacheTime = null, $cachePath = null, $contentType = "text/html", $charset = "", $show = true) { $this->getViewObj(); return $this->view->fetch($tplFile, $cacheTime, $cachePath = null, $contentType, $charset); } protected function isCache($cachePath = null) { $args = func_get_args(); $this->getViewObj(); return call_user_func_array(array($this->view, "isCache"), $args); } protected function assign($name, $value) { $this->getViewObj(); return $this->view->assign($name, $value); } protected function error($msg = "", $url = "", $time = 2, $tpl = null) { $msg = $msg ? $msg : L("control_error_msg"); $tpl_file = $tpl ? $tpl : C("TPL_ERROR"); $this->_error_success($msg, $url, $time, $tpl_file); } protected function success($msg = NULL, $url = NULL, $time = 2, $tpl = null) { $msg = $msg ? $msg : L("control_success_msg"); $tpl_file = $tpl ? $tpl : C("TPL_SUCCESS"); $this->_error_success($msg, $url, $time, $tpl_file); exit; } private function _error_success($msg, $url, $time, $tpl_file) { $time = is_numeric($time) ? $time : 3; if (empty($url)) { $url = "window.history.back(-1);"; } else { $url = "window.location.href='" . U($url) . "'"; } $style_conf = C('TPL_STYLE') ? '/' . C('TPL_STYLE') . '/' : '/'; $tpl_dir = strstr(C("TPL_DIR"), '/') ? C("TPL_DIR") . $style_conf : APP_PATH . C("TPL_DIR") . $style_conf . 'Public/'; $tpl = strstr($tpl_file, '/') ? $tpl_file : $tpl_dir . $tpl_file; $this->assign("msg", $msg); $this->assign("url", $url); $this->assign("time", $time); $this->display($tpl); exit; } protected function _ajax($data, $type = "JSON") { $type = strtoupper($type); switch ($type) { case "HTML": case "TEXT": $_data = $data; break; case "XML": $_data = Xml::create($data, "root", "UTF-8"); break; default: $_data = json_encode($data); } echo $_data; exit; } public function __destruct() { event("CONTROL_END", $this->options); } }final class debug { static $info = array(); static $runtime; static $memory; static $memory_peak; static $sqlExeArr = array(); static $tpl = array(); static $cache=array("write_s"=>0,"write_f"=>0,"read_s"=>0,"read_f"=>0); static public function start($start) { self::$runtime[$start] = microtime(true); if (function_exists("memory_get_usage")) { self::$memory[$start] = memory_get_usage(); } if (function_exists("memory_get_peak_usage")) { self::$memory_peak[$start] = false; } } static public function runtime($start, $end = '', $decimals = 4) { if (!isset(self::$runtime[$start])) { throw new exceptionHD(L("_nohavedebugstart") . $start); } if (empty(self::$runtime[$end])) { self::$runtime[$end] = microtime(true); return number_format(self::$runtime[$end] - self::$runtime[$start], $decimals); } } static public function memory_perk($start, $end = '') { if (!isset(self::$memory_peak[$start])) return mt_rand(200000, 1000000); if (!empty($end)) self::$memory_peak[$end] = memory_get_peak_usage(); return max(self::$memory_peak[$start], self::$memory_peak[$end]); } static public function show($start, $end) { $debug = array(); $debug['file'] = require_cache(); $debug['runtime'] = self::runtime($start, $end); $debug['memory'] = number_format(self::memory_perk($start, $end) / 1000, 0) . " KB"; include(HDPHP_TPL_PATH . '/debug.html'); } }abstract class Event { abstract function run(&$param); protected $options = array(); public function __construct() { if (!empty($this->options)) { foreach ($this->options as $name => $value) { if (is_null(C($name))) { C($name, $this->options[$name]); } else { $this->options[$name] = C($name); } } } } }final class HDPHP { static public function init() { IS_GROUP and Route::group(); define("APP", ucfirst(IS_GROUP ? $_GET[C('VAR_APP')] : basename(substr(APP_PATH, 0, -1)))); $group = isset($_GET[C("VAR_GROUP")]) ? $_GET[C("VAR_GROUP")] : C("DEFAULT_GROUP"); define("APP_GROUP", $group); IS_GROUP and define("APP_PATH", GROUP_PATH . APP_GROUP . '/' . APP . '/'); defined("CONTROL_PATH") or define("CONTROL_PATH", APP_PATH . 'Control/'); defined("MODEL_PATH") or define("MODEL_PATH", APP_PATH . 'Model/'); defined("CONFIG_PATH") or define("CONFIG_PATH", APP_PATH . 'Config/'); defined("EVENT_PATH") or define("EVENT_PATH", APP_PATH . 'Event/'); defined("LANGUAGE_PATH") or define("LANGUAGE_PATH", APP_PATH . 'Language/'); defined("TAG_PATH") or define("TAG_PATH", APP_PATH . 'Tag/'); defined("LIB_PATH") or define("LIB_PATH", APP_PATH . 'Lib/'); defined("COMPILE_PATH") or define("COMPILE_PATH", TEMP_PATH . (IS_GROUP ? APP_GROUP.'/'.APP . '/Compile/' : 'Compile/')); defined("CACHE_PATH") or define("CACHE_PATH", TEMP_PATH . (IS_GROUP ? APP_GROUP.'/'.APP . '/Cache/' : 'Cache/')); defined("TABLE_PATH") or define("TABLE_PATH", TEMP_PATH . (IS_GROUP ? APP_GROUP.'/'.APP . '/Table/' : 'Table/')); defined("LOG_PATH") or define("LOG_PATH", TEMP_PATH . 'Log/'); $app_config = CONFIG_PATH . 'config.php'; if (is_file($app_config)) C(require($app_config)); date_default_timezone_set(C("DEFAULT_TIME_ZONE")); $tpl = rtrim(C("TPL_DIR"), '/'); $tpl_style = rtrim(C("TPL_STYLE"), '/'); define("TPL_PATH", (strstr($tpl, '/') ? $tpl . '/' : APP_PATH . $tpl . '/') . ($tpl_style ? $tpl_style . '/' : $tpl_style)); define("PUBLIC_PATH", TPL_PATH . 'Public/'); Route::app(); @ini_set('memory_limit', '128M'); @ini_set("register_globals", "off"); @ini_set('magic_quotes_runtime', 0); define('NOW', $_SERVER['REQUEST_TIME']); define("NOW_MICROTIME", microtime(true)); define("MAGIC_QUOTES_GPC", @get_magic_quotes_gpc() ? true : false); define('REQUEST_METHOD', $_SERVER['REQUEST_METHOD']); define('IS_GET', REQUEST_METHOD == 'GET' ? true : false); define('IS_POST', REQUEST_METHOD == 'POST' ? true : false); define('IS_PUT', REQUEST_METHOD == 'PUT' ? true : false); define("IS_AJAX", ajax_request()); define('IS_DELETE', REQUEST_METHOD == 'DELETE' ? true : false); spl_autoload_register(array(__CLASS__, "autoload")); set_error_handler(array(__CLASS__, "error"), E_ALL); set_exception_handler(array(__CLASS__, "exception")); O("Session" . ucwords(C("SESSION_ENGINE")), "run"); !ini_get("session.auto_start") and C("SESSION_AUTO") and session_start(); is_file(COMMON_LANGUAGE_PATH . C('LANGUAGE') . '.php') and L(require COMMON_LANGUAGE_PATH . C('LANGUAGE') . '.php'); is_file(LANGUAGE_PATH . C('LANGUAGE') . '.php') and L(require LANGUAGE_PATH . C('LANGUAGE') . '.php'); C("CORE_EVENT", require HDPHP_CONFIG_PATH . "event.php"); IS_GROUP and is_file(COMMON_CONFIG_PATH . 'event.php') and C("GROUP_EVENT", require COMMON_CONFIG_PATH . 'event.php'); is_file(CONFIG_PATH . 'event.php') and C("APP_EVENT", require CONFIG_PATH . 'event.php'); IS_GROUP and is_file(COMMON_LIB_PATH . 'Alias.php') and alias_import(COMMON_LIB_PATH . 'Alias.php'); is_file(LIB_PATH . 'Alias.php') and alias_import(LIB_PATH . 'Alias.php'); } static public function autoload($className) { $class = ucfirst($className) . '.class.php'; if (substr($className, -5) == "Model") { if (require_array(array( HDPHP_DRIVER_PATH . 'Model/' . $class, MODEL_PATH . $class, COMMON_MODEL_PATH . $class )) ) return; } elseif (substr($className, -7) == "Control") { if (require_array(array( HDPHP_CORE_PATH . $class, CONTROL_PATH . $class, COMMON_CONTROL_PATH . $class )) ) return; } elseif (substr($className, 0, 2) == 'Db') { if (require_array(array( HDPHP_DRIVER_PATH . 'Db/' . $class )) ) return; } elseif (substr($className, 0, 5) == "Cache") { if (require_array(array( HDPHP_DRIVER_PATH . 'Cache/' . $class, )) ) return; } elseif (substr($className, 0,4) == "View") { if (require_array(array( HDPHP_DRIVER_PATH . 'View/' . $class, )) ) return; }elseif (substr($className, 0, 7) == "Session") { if (require_array(array( HDPHP_DRIVER_PATH . 'Session/' . $class )) ) return; } elseif (substr($className, -5) == "Event") { if (require_array(array( EVENT_PATH . $class, COMMON_EVENT_PATH . $class )) ) return; } elseif (substr($className, -3) == "Tag") { if (require_array(array( TAG_PATH . $class, COMMON_TAG_PATH . $class )) ) return; } elseif (alias_import($className)) { return; } elseif (require_array(array( EVENT_PATH . $class, LIB_PATH . $class, TAG_PATH . $class, COMMON_LIB_PATH . $class, HDPHP_CORE_PATH . $class, HDPHP_EXTEND_PATH . $class, HDPHP_EXTEND_PATH . '/Tool/' . $class )) ) { return; } $msg = "Class {$class} not found"; Log::write($msg); error($msg); } static public function exception($e) { $error = array(); $error['message'] = $e->getMessage(); $trace = $e->getTrace(); if ($trace[0]['function'] == 'throw_exception') { $error['file'] = $trace[0]['file']; $error['line'] = $trace[0]['line']; } else { $error['file'] = $e->getFile(); $error['line'] = $e->getLine(); } error($error); } static public function error($errno, $error, $file, $line) { $errorType = substr(FriendlyErrorType($errno), 2); $msg = "[$errorType]" . $error . ' [TIME]' . date("Y-m-d h:i:s") . ' [FILE]' . $file . ' [LINE]' . $line; switch ($errno) { case E_ERROR: case E_PARSE: case E_USER_ERROR: error($msg); break; case E_USER_WARNING: case E_USER_NOTICE: default: Log::set($msg, $errno); if (DEBUG && C("DEBUG_SHOW")) include HDPHP_TPL_PATH . 'notice.html'; break; } } }final class HdException extends Exception { }class Log { static $log = array(); static public function set($message, $logType) { $type = substr(FriendlyErrorType($logType), 2); if (in_array($type, array_change_value_case(C("LOG_TYPE"), 1))) { self::$log[] = $message . "\n"; } } static public function save($type = 3, $destination = NULL, $extraHeaders = NULL) { if (is_null($destination)) { $destination = LOG_PATH . date("Y-m-d") . '-' . substr(md5(C("LOG_KEY")), 0, 5) . ".log"; } if ($type == 3) { if (is_file($destination) && filesize($destination) > C("LOG_SIZE")) { $num = count(glob(LOG_PATH . date("Y-m-d") . '-' . substr(md5(C("LOG_KEY")), 0, 5) . "-*")); rename($destination, substr($destination, 0, -4) . "-" . $num . ".log"); } } is_dir(LOG_PATH) or @dir_create(LOG_PATH); error_log(implode("", self::$log), $type, $destination, $extraHeaders); self::$log = array(); } static public function write($message, $type = 3, $destination = NULL, $extraHeaders = NULL) { Dir::create(LOG_PATH); if (is_null($destination)) { $destination = LOG_PATH . date("Y-m-d") . '-' . substr(md5(C("LOG_KEY")), 0, 5) . ".log"; } if ($type == 3) { if (is_file($destination) && filesize($destination) > C("LOG_SIZE")) { $num = count(glob(LOG_PATH . date("Y-m-d") . '-' . substr(md5(C("LOG_KEY")), 0, 5) . "-*")); rename($destination, substr($destination, 0, -4) . "-" . $num . ".log"); } } is_dir(LOG_PATH) or @dir_create(LOG_PATH); error_log($message."\n", $type, $destination, $extraHeaders = null); } }final class Route { static public function group() { $query = C('URL_TYPE') == 3 && isset($_GET[C("PATHINFO_VAR")]) ? $_GET[C("PATHINFO_VAR")] : (isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : $_SERVER['QUERY_STRING']); $url = self::parseRoute(str_ireplace(C('PATHINFO_HTML'), '', trim($query, '/'))); $gets = ''; if (!empty($_SERVER['PATH_INFO']) || (C('URL_TYPE') == 3 && isset($_GET[C("PATHINFO_VAR")]))) { $url = str_replace(array('&', '='), C("PATHINFO_DLI"), $url); } else { parse_str($url, $gets); $_GET = array_merge($_GET, $gets); } $args = $gets || empty($url) ? array() : explode(C("PATHINFO_DLI"), $url); $a = C("VAR_APP"); if (isset($_GET[$a])) { } elseif (isset($args[0])) { if ($args[0] == $a) { $_GET[$a] = $args[1]; } else { $_GET[$a] = $args[0]; } } else { $_GET[$a] = C("DEFAULT_APP"); } } static public function app() { $query = C('URL_TYPE') == 3 && isset($_GET[C("PATHINFO_VAR")]) ? $_GET[C("PATHINFO_VAR")] : (isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : $_SERVER['QUERY_STRING']); $url = self::parseRoute(str_ireplace(C('PATHINFO_HTML'), '', trim($query, '/'))); $gets = ''; if (!empty($_SERVER['PATH_INFO']) || (C('URL_TYPE') == 3 && isset($_GET[C("PATHINFO_VAR")]))) { $url = str_replace(array('&', '='), C("PATHINFO_DLI"), $url); } else { parse_str($url, $gets); $_GET = array_merge($_GET, $gets); } $args = $gets || empty($url) ? array() : explode(C("PATHINFO_DLI"), $url); if (IS_GROUP && !empty($args)) { if ($args[0] == C("VAR_APP")) { array_shift($args); array_shift($args); } else { array_shift($args); } } if (isset($_GET[C("VAR_CONTROL")])) { } elseif (isset($args[0]) && !empty($args[0])) { if ($args[0] == C("VAR_CONTROL")) { $_GET[C("VAR_CONTROL")] = $args[1]; array_shift($args); array_shift($args); } else { $_GET[C("VAR_CONTROL")] = $args[0]; array_shift($args); } } else { $_GET[C('VAR_CONTROL')] = C('DEFAULT_CONTROL'); } if (isset($_GET[C("VAR_METHOD")])) { } elseif (isset($args[0]) && !empty($args[0])) { if ($args[0] == C("VAR_METHOD")) { $_GET[C("VAR_METHOD")] = $args[1]; array_shift($args); array_shift($args); } else { $_GET[C("VAR_METHOD")] = $args[0]; array_shift($args); } } else { $_GET[C('VAR_METHOD')] = C('DEFAULT_METHOD'); } $_GET[C('VAR_CONTROL')] = ucwords(preg_replace('@_([a-z]?)@ei', 'strtoupper("\1")', $_GET[C('VAR_CONTROL')])); if (!empty($args)) { $count = count($args); for ($i = 0; $i < $count;) { $_GET[$args [$i]] = isset($args [$i + 1]) ? $args [$i + 1] : ''; $i += 2; } } if (C('URL_TYPE') == 2) { unset($_GET[C('PATHINFO_VAR')]); } self::setConst(); } static private function setConst() { $host = $_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME']; define("__HOST__", C("HTTPS") ? "https://" : "http://" . trim($host, '/')); $documentRoot = str_ireplace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_FILENAME'])); $root = empty($documentRoot) ? "" : '/' . trim(str_replace('\\', '/', $documentRoot), '/'); define("__ROOT__", __HOST__ . $root); $url = isset($_SERVER['REDIRECT_URL']) ? rtrim(dirname($_SERVER['SCRIPT_NAME']), '/') : $_SERVER['SCRIPT_NAME']; define("__WEB__", __HOST__ . $url); define("__URL__", __HOST__ . '/' . trim($_SERVER['REQUEST_URI'], '/')); define("__HDPHP__", __HOST__ . '/' . trim(str_ireplace(str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']), "", HDPHP_PATH), '/')); define("__HDPHP_DATA__", __HDPHP__ . '/Data'); define("__HDPHP_TPL__", __HDPHP__ . '/Lib/Tpl'); define("__HDPHP_EXTEND__", __HDPHP__ . '/Extend'); define("CONTROL", $_GET[C('VAR_CONTROL')]); define("METHOD", $_GET[C('VAR_METHOD')]); switch (C("URL_TYPE")) { case 2: define("__APP__", __WEB__ . (IS_GROUP ? '?' . C('VAR_APP') . '=' . APP : '')); define("__CONTROL__", __APP__ . (IS_GROUP ? '&' . C('VAR_CONTROL') . '=' . CONTROL : '?c=' . CONTROL)); define("__METH__", __CONTROL__ . '&' . C('VAR_METHOD') . '=' . METHOD); break; case 3: define("__APP__", __WEB__ . '?' . C("PATHINFO_VAR") . '=' . (IS_GROUP ? '/' . APP : '')); define("__CONTROL__", __APP__ . '/' . CONTROL); define("__METH__", __CONTROL__ . '/' . METHOD); break; case 1: default: define("__APP__", __WEB__ . (IS_GROUP ? '/' . APP : '')); define("__CONTROL__", __APP__ . '/' . CONTROL); define("__METH__", __CONTROL__ . '/' . METHOD); break; } if (defined("GROUP_PATH")) defined("__GROUP__") or define("__GROUP__", __ROOT__ . '/' . str_ireplace(ROOT_PATH, '', str_replace('\\', '/', realpath(GROUP_PATH)))); defined("__TPL__") or define("__TPL__", __ROOT__ . '/' . str_ireplace(ROOT_PATH, '', str_replace('\\', '/', realpath(TPL_PATH)))); defined("__CONTROL_TPL__") or define("__CONTROL_TPL__", __TPL__ . '/' . CONTROL); defined("__STATIC__") or define("__STATIC__", __TPL__ . '/Static'); defined("__PUBLIC__") or define("__PUBLIC__", __TPL__ . '/Public'); defined("__COMMON__") or define("__COMMON__", __ROOT__ . '/Common'); } static private function parseRoute($query) { $route = C("ROUTE"); if (!$route or !is_array($route)) return $query; foreach ($route as $k => $v) { if (preg_match("@^/.*/[isUx]*$@i", $k)) { if (preg_match($k, $query)) { $v = str_replace('#', '\\', $v); return preg_replace($k, $v, $query); } continue; } $search = array( '@(:year)@i', '@(:month)@i', '@(:day)@i', '@(:num)@i', '@(:any)@i', '@(:[a-z0-9]+\\\d)@i', '@(:[a-z0-9]+\\\w)@i', '@(:[a-z0-9]+)@i' ); $replace = array( '\d{4}', '\d{1,2}', '\d{1,2}', '\d+', '.+', '\d+', '\w+', '([a-z0-9]+)' ); $base_preg = "@^" . preg_replace($search, $replace, $k) . "$@i"; if (!preg_match($base_preg, $query)) { continue; } if (!strstr($k, ":")) { return $v; } $vars = ""; preg_match('/[^:\sa-z0-9]/i', $k, $vars); if (isset($vars[0])) { $roles_ex = explode($vars[0], $k); $url_args = explode($vars[0], $query); } else { $roles_ex = array($k); $url_args = array($query); } $query = $v; foreach ($roles_ex as $m => $n) { if (!strstr($n, ":")) { continue; } $_GET[str_replace(":", "", $n)] = $url_args[$m]; } return $query; } return $query; } static public function toUrl($url) { $route = C("route"); if (!$route) { return $url; } foreach ($route as $routeKey => $routeVal) { $routeKey = trim($routeKey); if (substr($routeKey, 0, 1) === '/') { $regGroup = array(); preg_match_all("@\(.*?\)@i", $routeKey, $regGroup, PREG_PATTERN_ORDER); $searchRegExp = $routeVal; for ($i = 0, $total = count($regGroup[0]); $i < $total; $i++) { $searchRegExp = str_replace('#' . ($i + 1), $regGroup[0][$i], $searchRegExp); } $urlArgs = array(); preg_match_all("@" . $searchRegExp . "@i", $url, $urlArgs, PREG_SET_ORDER); if ($urlArgs) { $routeUrl = trim(str_replace(array('/^', '$/'), '', $routeKey), '/'); foreach ($regGroup[0] as $k => $v) { $v = preg_replace('@([\*\$\(\)\+\?\[\]\{\}\\\])@', '\\\$1', $v); $routeUrl = preg_replace('@' . $v . '@', $urlArgs[0][$k + 1], $routeUrl, $count = 1); } return trim($routeUrl, '/'); } } else { $routeGetVars = array(); preg_match_all('/:([a-z]*)/i', $routeKey, $routeGetVars, PREG_PATTERN_ORDER); $getRouteUrl = $routeVal; switch (C("URL_TYPE")) { case 1: $getRouteUrl .= '/'; foreach ($routeGetVars[1] as $getK => $getV) { $getRouteUrl .= $getV . '/(.*)/'; } $getRouteUrl = '@' . trim($getRouteUrl, '/') . '@i'; break; case 2: $getRouteUrl .= '&'; foreach ($routeGetVars[1] as $getK => $getV) { $getRouteUrl .= $getV . '=(.*)' . '&'; } $getRouteUrl = '@' . trim($getRouteUrl, '&') . '@i'; break; } $getArgs = array(); preg_match_all($getRouteUrl, $url, $getArgs, PREG_SET_ORDER); if ($getArgs) { $newUrl = $routeKey; foreach ($routeGetVars[0] as $rk => $getName) { $newUrl = str_replace($getName, $getArgs[0][$rk + 1], $newUrl); } return $newUrl; } } } return $url; } static public function removeUrlParam($var, $url = null) { $pathinfo_dli = C("PATHINFO_DLI"); if (!is_null($url)) { $url_format = strstr($url, "&") ? $url . '&' : $url . $pathinfo_dli; $url = str_replace($pathinfo_dli, "###", $url_format); $search = array( "/$var" . "###" . ".*?" . "###" . "/", "/$var=.*?&/i", "/\?&/", "/&&/" ); $replace = array( "", "", "?", "" ); $url_replace = preg_replace($search, $replace, $url); $url_rtrim = rtrim(rtrim($url_replace, "&"), "###"); return str_replace("###", $pathinfo_dli, $url_rtrim); } $get = $_GET; unset($get[C("VAR_APP")]); unset($get[C("VAR_CONTROL")]); unset($get[C("VAR_METHOD")]); $url = ''; $url_type = C("URL_TYPE"); foreach ($get as $k => $v) { if ($k === $var) continue; if ($url_type == 1) { $url .= $pathinfo_dli . $k . $pathinfo_dli . $v; } else { $url .= "&" . $k . "=" . $v; } } $url_rtrim = trim(trim($url, $pathinfo_dli), '&'); $url_str = empty($url_rtrim) ? "" : $pathinfo_dli . $url_rtrim; if ($url_type == 1) { return __METH__ . $url_str; } else { return __METH__ . "&" . trim($url_str, "&"); } } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); function M($tableName = null, $full = null) { return new Model($tableName, $full); } function K($class, $table = false, $param = array()) { $table = $table === false ? strtolower($class) : $table; $class .= "Model"; return new $class($table, $param); } function R($tableName = null, $full = null) { return new relationModel($tableName, $full); } function V($tableName = null, $full = null) { return new ViewModel($tableName, $full); } function F($name, $value = false, $path = CACHE_PATH) { $_cache = array(); $cacheFile = rtrim($path, '/') . '/' . $name . '.php'; if (is_null($value)) { if (is_file($cacheFile)) { unlink($cacheFile); unset($_cache[$name]); } return true; } if ($value === false) { if (isset($_cache[$name])) return $_cache[$name]; return is_file($cacheFile) ? include $cacheFile : null; } $data = "<?php if(!defined('HDPHP_PATH'))exit;\nreturn " . compress(var_export($value, true)) . ";\n?>"; is_dir($path) || dir_create($path); if (!file_put_contents($cacheFile, $data)) { return false; } $_cache[$name] = $data; return true; } function S($name, $value = false, $expire = null, $options = array()) { static $_data = array(); $cacheObj = Cache::init($options); if (is_null($value)) { return $cacheObj->del($name); } $driver = isset($options['Driver']) ? $options['Driver'] : ''; $key = $name . $driver; if ($value === false) { if (isset($_data[$key])) { Debug::$cache['read_s']++; return $_data[$key]; } else { return $cacheObj->get($name, $expire); } } $cacheObj->set($name, $value, $expire); $_data[$key] = $value; return true; } function A($arg, $args = array()) { $arg = trim($arg, '/'); $pathArr = explode('/', trim($arg, '/')); switch (count($pathArr)) { case 1: $base = CONTROL_PATH . CONTROL; $method = $pathArr[0]; break; case 2: $base = CONTROL_PATH . $pathArr[0]; $method = $pathArr[1]; break; case 3: $base = APP_PATH . '../' . $pathArr[0] . '/Control/' . $pathArr[1]; $method = $pathArr[2]; break; } $class = basename($base) . C('CONTROL_FIX'); if (require_cache($base . C('CONTROL_FIX') . '.class.php')) { if (class_exists($class)) { $obj = new $class (); if (method_exists($class, $method)) { if (empty($args)) { return $obj->$method(); } else { return call_user_func_array(array(&$obj, $method), $args); } } } } } function import($class = null, $base = null, $ext = ".class.php") { $class = str_replace(".", "/", $class); if (is_null($base)) { $info = explode("/", $class); if ($info[0] == '@' || APP == $info[0]) { $base = APP_PATH; $class = substr_replace($class, '', 0, strlen($info[0]) + 1); } elseif (strtoupper($info[0]) == 'HDPHP') { $base = dirname(substr_replace($class, HDPHP_PATH, 0, 6)); $class = basename($class); } elseif (in_array(strtoupper($info[0]), array("LIB", "ORG"))) { $base = APP_PATH; } else { $base = APP_PATH . '../' . $info[0] . '/'; $class = substr_replace($class, '', 0, strlen($info[0]) + 1); } } if (substr($base, -1) != '/') $base .= '/'; $file = $base . $class . $ext; if (!class_exists($class, false)) { return require_cache($file); } return true; } function O($class, $method = null, $args = array()) { $path = $class; $tmp = explode(".", $class); $class = array_pop($tmp); if (!class_exists($class, false)) { import($path); } $obj = new $class (); if (!is_object($obj)) return false; if ($method && method_exists($obj, $method)) { if (empty($args)) { $args = array(); } else if (!is_array($args)) { error("O()函数第3个参数必须为数组，你也可以不传"); } return call_user_func_array(array($obj, $method), $args); } else { return $obj; } } function control($control, $method = NULl, $args = array()) { $pathArr = explode('/', trim($control, '/')); switch (count($pathArr)) { case 1: $base = CONTROL_PATH . $pathArr[0]; break; case 2: $base = APP_PATH . '../' . $pathArr[0] . '/Control/' . $pathArr[1]; break; } $class = basename($base) . C('CONTROL_FIX'); if (require_cache($base . C('CONTROL_FIX') . '.class.php')) { if (class_exists($class)) { $obj = new $class (); if ($method && method_exists($obj, $method)) { return call_user_func_array(array(&$obj, $method), $args); } return $obj; } } return false; } function session($name = false, $value = '') { static $_start = false; if ($name === false) return $_SESSION; if ($_start === false) { $_start = true; session_id() || session_start(); } if (is_null($name)) { $_SESSION = array(); session_unset(); session_destroy(); } elseif (is_null($value)) { unset($_SESSION[$name]); } elseif (empty($value)) { switch (strtolower($name)) { case "[parse]": session_write_close(); break; } return isset($_SESSION[$name]) ? $_SESSION[$name] : null; } else { $_SESSION[$name] = $value; } } function C($name = null, $value = null) { static $config = array(); if (is_null($name)) { return $config; } if (is_array($value)) { $value = array_change_key_case_d($value); } if (is_string($name)) { $name = strtolower($name); if (!strstr($name, '.')) { if (is_null($value)) { if (isset($config[$name]) && !is_array($config[$name])) { $config[$name] = trim($config[$name]); } return isset($config [$name]) ? $config [$name] : null; } if ($name == 'language') { is_file(COMMON_LANGUAGE_PATH . $value . '.php') and L(require COMMON_LANGUAGE_PATH . $value . '.php'); is_file(LANGUAGE_PATH . $value . '.php') and L(require LANGUAGE_PATH . $value . '.php'); } $config [$name] = isset($config[$name]) && is_array($config[$name]) && is_array($value) ? array_merge($config[$name], $value) : $value; return $config[$name]; } $name = array_change_key_case_d(explode(".", $name), 0); if (is_null($value)) { return isset($config [$name[0]] [$name[1]]) ? $config [$name[0]][$name[1]] : null; } $config [$name[0]] [$name[1]] = $value; } if (is_array($name)) { $config = array_merge($config, array_change_key_case_d($name, 0)); return true; } } function L($name = null, $value = null) { static $languge = array(); if (is_null($name)) { return $languge; } if (is_string($name)) { $name = strtolower($name); if (!strstr($name, '.')) { if (is_null($value)) return isset($languge [$name]) ? $languge [$name] : null; $languge [$name] = $value; return $languge[$name]; } $name = array_change_key_case_d(explode(".", $name), 0); if (is_null($value)) { return isset($languge [$name[0]] [$name[1]]) ? $languge [$name[0]][$name[1]] : null; } $languge [$name[0]] [$name[1]] = $value; } if (is_array($name)) { $languge = array_merge($languge, array_change_key_case_d($name)); return true; } } function event($name, &$param = array()) { $core = C("CORE_EVENT." . $name); $group = C("GROUP_EVENT." . $name); $event = C("APP_EVENT." . $name); if (is_array($group)) { if ($core) { $group = array_merge($core, $group); } } else { $group = $core; } if (is_array($group)) { if ($event) { $event = array_merge($group, $event); } else { $event = $group; } } if (is_array($event)) { foreach ($event as $e) { E($e, $param); } } } function Q($var, $default = null, $filter = null) { $var = explode(".", $var); if (count($var) == 1) { array_unshift($var, 'get'); } $var[0] = strtolower($var[0]); switch (strtolower($var[0])) { case 'get' : $data = & $_GET; break; case 'post' : $data = & $_POST; break; case 'request' : $data = & $_REQUEST; break; case 'files' : $data = & $_FILES; break; case 'session' : $data = & $_SESSION; break; case 'cookie' : $data = & $_COOKIE; break; case 'server' : $data = & $_SERVER; break; case 'globals' : $data = & $GLOBALS; break; default: throw_exception($var[0] . 'Q方法参数错误'); } if (empty($var[1])) { return $data; } else if (isset($data[$var[1]])) { $value = $data[$var[1]]; if (is_null($filter)) { return $value; } $funcArr = !empty($filter) ? $filter : C("FILTER_FUNCTION"); if (!empty($funcArr)) { if (is_string($funcArr)) { $funcArr = explode(",", $funcArr); } foreach ($funcArr as $func) { if (!function_exists($func)) continue; $value = is_array($value) ? array_map($func, $value) : $func($value); } $data[$var[1]] = $value; return $value; } return $value; } else { $data[$var[1]] = $default; return $default; } } function E($name, &$params = null) { $class = $name . "Event"; $event = new $class; $event->run($params); } function show($var) { if (is_bool($var)) { var_dump($var); } else if (is_null($var)) { var_dump(NULL); } else { echo "<pre>" . print_r($var, true) . "</pre>"; } } function p($var) { show($var); } function dump($var) { show($var); } function go($url, $time = 0, $msg = '') { $url = U($url); if (!headers_sent()) { $time == 0 ? header("Location:" . $url) : header("refresh:{$time};url={$url}"); exit($msg); } else { echo "<meta http-equiv='Refresh' content='{$time};URL={$url}'>"; if ($time) exit($msg); } } function ip_get_client($type = 0) { $type = intval($type); $ip = ''; if (isset($_SERVER)) { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; } else if (isset($_SERVER["HTTP_CLIENT_IP"])) { $ip = $_SERVER["HTTP_CLIENT_IP"]; } else { $ip = $_SERVER["REMOTE_ADDR"]; } } else { if (getenv("HTTP_X_FORWARDED_FOR")) { $ip = getenv("HTTP_X_FORWARDED_FOR"); } else if (getenv("HTTP_CLIENT_IP")) { $ip = getenv("HTTP_CLIENT_IP"); } else { $ip = getenv("REMOTE_ADDR"); } } $long = ip2long($ip); $clientIp = $long ? array($ip, $long) : array("0.0.0.0", 0); return $clientIp[$type]; } function ajax_request() { if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') return true; return false; } function addslashes_d($data) { if (is_string($data)) { return addslashes($data); } if (is_numeric($data)) { return $data; } if (is_array($data)) { $var = array(); foreach ($data as $k => $v) { if (is_array($v)) { $var[$k] = addslashes_d($v); continue; } else { $var[$k] = addslashes($v); } } return $var; } } function stripslashes_d($data) { if (empty($data)) { return $data; } elseif (is_string($data)) { return stripslashes($data); } elseif (is_array($data)) { $var = array(); foreach ($data as $k => $v) { if (is_array($v)) { $var[$k] = stripslashes_d($v); continue; } else { $var[$k] = stripslashes($v); } } return $var; } } function array_to_String($array, $level = 0) { if (!is_array($array)) { return "'" . $array . "'"; } $space = ''; for ($i = 0; $i <= $level; $i++) { $space .= "\t"; } $arr = "Array\n$space(\n"; $c = $space; foreach ($array as $k => $v) { $k = is_string($k) ? '\'' . addcslashes($k, '\'\\') . '\'' : $k; $v = !is_array($v) && (!preg_match("/^\-?[1-9]\d*$/", $v) || strlen($v) > 12) ? '\'' . addcslashes($v, '\'\\') . '\'' : $v; if (is_array($v)) { $arr .= "$c$k=>" . array_to_String($v, $level + 1); } else { $arr .= "$c$k=>$v"; } $c = ",\n$space"; } $arr .= "\n$space)"; return $arr; } if (!function_exists('json_encode')) { function json_encode($value) { $json = new json(); return $json->encode($value); } } if (!function_exists('json_decode')) { function json_decode($json_value, $bool = false) { $json = new json(); return $json->decode($json_value, $bool); } } function mobile_area($mobile) { require_cache(HDPHP_EXTEND_PATH . "Org/Mobile/Mobile.class.php"); return Mobile::area($mobile); } if (!function_exists('image_type_to_extension')) { function image_type_to_extension($type, $dot = true) { $e = array(1 => 'gif', 'jpeg', 'png', 'swf', 'psd', 'bmp', 'tiff', 'tiff', 'jpc', 'jp2', 'jpf', 'jb2', 'swc', 'aiff', 'wbmp', 'xbm'); $type = (int)$type; return ($dot ? '.' : '') . $e[$type]; } } function rand_str($len = 6) { $data = 'abcdefghijklmnopqrstuvwxyz0123456789'; $str = ''; while (strlen($str) < $len) $str .= substr($data, mt_rand(0, strlen($data) - 1), 1); return $str; } function encrypt($data, $key = null) { return encry::encrypt($data, $key); } function decrypt($data, $key = null) { return encry::decrypt($data, $key); } function data_format(&$data, $func = null) { $functions = is_null($func) ? C("FILTER_FUNCTION") : $func; if (!is_array($functions)) { $functions = preg_split("/\s*,\s*/", $functions); } foreach ($functions as $_func) { if (is_string($data)) { $data = $_func($data); } else if (is_array($data)) { foreach ($data as $k => $d) { $data[$k] = is_array($d) ? data_format($d, $functions) : $_func($d); } } } return $data; } function _default($varName, $value = "") { return isset($varName) ? $varName : $value; } function _request($method, $varName = null, $html = true) { $method = strtolower($method); switch ($method) { case 'ispost' : case 'isget' : case 'ishead' : case 'isdelete' : case 'isput' : return strtolower($_SERVER['REQUEST_METHOD']) == strtolower(substr($method, 2)); case 'get' : $data = & $_GET; break; case 'post' : $data = & $_POST; break; case 'request' : $data = & $_REQUEST; break; case 'Session' : $data = & $_SESSION; break; case 'cookie' : $data = & $_COOKIE; break; case 'server' : $data = & $_SERVER; break; case 'globals' : $data = & $GLOBALS; break; default: throw_exception('abc'); } if (is_null($varName)) return $data; if (isset($data[$varName]) && $html) { $data[$varName] = htmlspecialchars($data[$varName]); } return isset($data[$varName]) ? $data[$varName] : null; } function set_http_state($code) { $state = array( 200 => 'OK', 301 => 'Moved Permanently', 302 => 'Moved Temporarily ', 400 => 'Bad Request', 403 => 'Forbidden', 404 => 'Not Found', 500 => 'Internal Server Error', 503 => 'Service Unavailable', ); if (isset($state[$code])) { header('HTTP/1.1 ' . $code . ' ' . $state[$code]); header('Status:' . $code . ' ' . $state[$code]); } } function is_ssl() { if (isset($_SERVER['HTTPS']) && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS']))) { return true; } elseif (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'])) { return true; } return false; } function print_const($view = true, $tplConst = false) { $define = get_defined_constants(true); $const = $define['user']; if ($tplConst) { $const = array(); foreach ($define['user'] as $k => $d) { if (preg_match('/^__/', $k)) { $const[$k] = $d; } } } if ($view) { p($const); } else { return $const; } } function date_before($time, $unit = null) { $time = intval($time); $unit = is_null($unit) ? array("年", "月", "星期", "日", "小时", "分钟", "秒") : $unit; switch (true) { case $time < (NOW - 31536000): return floor((NOW - $time) / 31536000) . $unit[0] . '前'; case $time < (NOW - 2592000): return floor((NOW - $time) / 2592000) . $unit[1] . '前'; case $time < (NOW - 604800): return floor((NOW - $time) / 604800) . $unit[2] . '前'; case $time < (NOW - 86400): return floor((NOW - $time) / 86400) . $unit[3] . '前'; case $time < (NOW - 3600): return floor((NOW - $time) / 3600) . $unit[4] . '前'; case $time < (NOW - 60): return floor((NOW - $time) / 60) . $unit[5] . '前'; default: return floor(NOW - $time) . $unit[6] . '前'; } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); function U($pathinfo, $args = array()) { if (preg_match("/^https?:\/\//i", $pathinfo)) return $pathinfo; $end = strpos($pathinfo, '.php'); if ($end) { $web = __ROOT__ . '/' . substr($pathinfo, 0, $end + 4); $pathinfo = substr($pathinfo, $end + 4); } else { $web = __WEB__; } if (is_string($args)) { parse_str($args, $args); } $parseUrl = parse_url(trim($pathinfo, '/')); $path = trim($parseUrl['path'], '/'); if (isset($parseUrl['query'])) { parse_str($parseUrl['query'], $query); $args = array_merge($query, $args); } $gets = array(); if (is_array($args)) { foreach ($args as $n => $q) { array_push($gets, $n); array_push($gets, $q); } } $vars = explode("/", $path); $urlType = C("URL_TYPE"); switch ($urlType) { case 1: $root = $web . '/'; break; case 2: $root = $web . '?'; break; } $set_app_group = false; if (defined("GROUP_PATH")) { $set_app_group = true; } $data = array(); switch (count($vars)) { case 2: if ($set_app_group) { $data[] = C("VAR_APP"); $data[] = APP; } $data[] = C("VAR_CONTROL"); $data[] = array_shift($vars); $data[] = C("VAR_METHOD"); $data[] = array_shift($vars); break; case 1: if ($set_app_group) { $data[] = C("VAR_APP"); $data[] = APP; } $data[] = C("VAR_CONTROL"); $data[] = CONTROL; $data[] = C("VAR_METHOD"); $data[] = array_shift($vars); break; default: $data[] = C("VAR_APP"); $data[] = array_shift($vars); $data[] = C("VAR_CONTROL"); $data[] = array_shift($vars); $data[] = C("VAR_METHOD"); $data[] = array_shift($vars); if (is_array($vars)) { foreach ($vars as $v) { $data[] = $v; } } } $varsAll = array_merge($data, $gets); $url = ''; switch ($urlType) { case 1: foreach ($varsAll as $value) { $url .= C('PATHINFO_Dli') . $value; } $url = str_replace(array("/" . C("VAR_APP") . "/", "/" . C("VAR_CONTROL") . "/", "/" . C("VAR_METHOD") . "/"), "/", $url); $url = substr($url, 1); break; case 2: foreach ($varsAll as $k => $value) { if ($k % 2) { $url .= '=' . $value; } else { $url .= '&' . $value; } } $url = substr($url, 1); break; } $pathinfo_html = $urlType === 1 ? '.' . trim(C("PATHINFO_HTML"), '.') : ''; if (C("URL_REWRITE")) { $root = preg_replace('/\w+?\.php\/?/i', '', $root); } return $root . Route::toUrl($url) . $pathinfo_html . C("PATHINFO_HTML"); } function N($name, $num = NULL) { static $data = array(); if (!isset($data[$name])) { $data[$name] = 0; } if (is_null($num)) { return $data[$name]; } else { $data[$name] += (int)$num; } } function md5_d($var) { return md5(serialize($var)); } function hash_hd($data, $len) { $hash = crc32($data) & 0xfffffff; return $hash % $len; } function dir_create($dirName, $auth = 0755) { $dirName = str_replace("\\", "/", $dirName); $dirPath = rtrim($dirName, '/'); if (is_dir($dirPath)) return true; $dirs = explode('/', $dirPath); $dir = ''; foreach ($dirs as $v) { $dir .= $v . '/'; is_dir($dir) or @mkdir($dir, $auth, true); } return is_dir($dirPath); } function require_cache($path = null) { static $_files = array(); if (is_null($path)) return $_files; if (isset($_files[$path])) { return true; } if (!file_exists_case($path)) { return false; } require($path); $_files[$path] = true; return true; } function load($file) { $file = str_replace(".", "/", preg_replace('@\.php@i', '', $file)); if (!strstr($file, '/')) { $app = LIB_PATH . $file . '.php'; $group = COMMON_LIB_PATH . $file . '.php'; return require_cache($app) || (IS_GROUP && require_cache($group)); } $info = explode('/', $file); if ($info[0] == '@' || APP == $info[0]) { $file = APP_PATH . substr_replace($file, '', 0, strlen($info[0]) + 1); } return require_cache($file); } function alias_import($name = null, $path = null) { static $_alias = array(); if (is_null($name)) return $_alias; if (is_string($name)) $name = strtolower($name); if (is_array($name)) { $_alias = array_merge($_alias, array_change_key_case($name)); return true; } elseif (!is_null($path)) { return $_alias[$name] = $path; } elseif (isset($_alias[$name])) { return require_cache($_alias[$name]); } return false; } function require_array($fileArr) { foreach ($fileArr as $file) { if (is_file($file) && require_cache($file)) return true; } return false; } function file_exists_case($file) { if (is_file($file)) { if (IS_WIN && C("CHECK_FILE_CASE")) { if (basename(realpath($file)) != basename($file)) { return false; } } return true; } return false; } function url_param_remove($var, $url = null) { return Route::removeUrlParam($var, $url); } function get_size($size, $decimals = 2) { switch (true) { case $size >= pow(1024, 3): return round($size / pow(1024, 3), $decimals) . " GB"; case $size >= pow(1024, 2): return round($size / pow(1024, 2), $decimals) . " MB"; case $size >= pow(1024, 1): return round($size / pow(1024, 1), $decimals) . " KB"; default: return $size . 'B'; } } function array_defined($arr) { foreach ($arr as $k => $v) { $k = strtoupper($k); if (is_string($v)) { define($k, $v); } elseif (is_numeric($v)) { defined($k, $v); } elseif (is_bool($v)) { $v = $v ? 'true' : 'false'; define($k, $v); } } return true; } function array_change_key_case_d($arr, $type = 0) { $function = $type ? 'strtoupper' : 'strtolower'; $newArr = array(); if (!is_array($arr) || empty($arr)) return $newArr; foreach ($arr as $k => $v) { $k = $function($k); if (is_array($v)) { $newArr[$k] = array_change_key_case_d($v, $type); } else { $newArr[$k] = $v; } } return $newArr; } function array_key_exists_d($key, $arr) { return array_key_exists(strtolower($key), array_change_key_case_d($arr)); } function array_to_object($arr) { if (!is_array($arr) || empty($arr)) { return null; } return (object)$arr; } function array_change_value_case($arr, $type = 0) { $function = $type ? 'strtoupper' : 'strtolower'; $newArr = array(); foreach ($arr as $k => $v) { if (is_array($v)) { $newArr[$k] = array_change_value_case($v, $type); } else { $newArr[$k] = $function($v); } } return $newArr; } function file_merge($files, $space = false, $tag = false) { $str = ''; foreach ($files as $file) { $con = trim(file_get_contents($file)); if ($space) $con = compress($con); $str .= substr($con, -2) == '?>' ? trim(substr($con, 5, -2)) : trim($con, 5); } return $tag ? '<?php if(!defined("HDPHP_PATH")){exit("No direct script access allowed");}' . $str . "\t?>" : $str; } function compress($content) { $str = ""; $data = token_get_all($content); $end = false; for ($i = 0, $count = count($data); $i < $count; $i++) { if (is_string($data[$i])) { $end = false; $str .= $data[$i]; } else { switch ($data[$i][0]) { case T_COMMENT: case T_DOC_COMMENT: break; case T_WHITESPACE: if (!$end) { $end = true; $str .= " "; } break; case T_START_HEREDOC: $str .= "<<<HDPHP\n"; break; case T_END_HEREDOC: $str .= "HDPHP;\n"; for ($m = $i + 1; $m < $count; $m++) { if (is_string($data[$m]) && $data[$m] == ';') { $i = $m; break; } if ($data[$m] == T_CLOSE_TAG) { break; } } break; default: $end = false; $str .= $data[$i][1]; } } } return $str; } function get_defines($name = "", $value = null, $type = 'user') { if ($name) { $const = get_defined_constants(); return defined($name) ? $const[$name] : $value; } $const = get_defined_constants(true); return $type === true ? $const : $const[$type]; } function throw_exception($msg, $type = "HdException", $code = 0) { if (class_exists($type)) { throw new $type($msg, $code); } else { error($msg); } } if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); function log_write($error) { $trace = debug_backtrace(); $e['message'] = $error; $e['file'] = $trace[0]['file']; $e['line'] = $trace[0]['line']; $e['class'] = isset($trace[0]['class']) ? $trace[0]['class'] : ""; $e['function'] = isset($trace[0]['function']) ? $trace[0]['function'] : ""; $msg = ("[Error]" . $e['message'] . " [Time]" . date("y-m-d h:i") . " [File]" . $e['file'] . " [Line]" . $e['line']); Log::write($msg); } function error($error) { $e = array(); if (!is_array($error)) { $trace = debug_backtrace(); $e['message'] = $error; $e['file'] = $trace[0]['file']; $e['line'] = $trace[0]['line']; $e['class'] = isset($trace[0]['class']) ? $trace[0]['class'] : ""; $e['function'] = isset($trace[0]['function']) ? $trace[0]['function'] : ""; ob_start(); debug_print_backtrace(); $e['trace'] = htmlspecialchars(ob_get_clean()); } else { $e = $error; } if (!DEBUG) { _404("[Error]" . $e['message'] . " [Time]" . date("y-m-d h:i") . " [File]" . $e['file'] . " [Line]" . $e['line']); } require HDPHP_TPL_PATH . 'halt.html'; exit; } function halt($error) { error($error); } function _404($msg = "", $filePath = "") { DEBUG && error($msg); Log::write($msg); Log::save(); if (empty($filePath) && C("404_TPL")) { $filePath = C("404_TPL"); } set_http_state(404); if (is_file($filePath) && is_readable($filePath)) { include $filePath; } exit; } function firephp($data) { ob_start(); $firephp = FirePHP::getInstance(true); $firephp->log($data, 'Iterators'); ob_flush(); ob_clean(); } function FriendlyErrorType($type) { switch ($type) { case E_ERROR: return 'E_ERROR'; case E_WARNING: return 'E_WARNING'; case E_PARSE: return 'E_PARSE'; case E_NOTICE: return 'E_NOTICE'; case E_CORE_ERROR: return 'E_CORE_ERROR'; case E_CORE_WARNING: return 'E_CORE_WARNING'; case E_CORE_ERROR: return 'E_COMPILE_ERROR'; case E_CORE_WARNING: return 'E_COMPILE_WARNING'; case E_USER_ERROR: return 'E_USER_ERROR'; case E_USER_WARNING: return 'E_USER_WARNING'; case E_USER_NOTICE: return 'E_USER_NOTICE'; case E_STRICT: return 'E_STRICT'; case E_RECOVERABLE_ERROR: return 'E_RECOVERABLE_ERROR'; case E_DEPRECATED: return 'E_DEPRECATED'; case E_USER_DEPRECATED: return 'E_USER_DEPRECATED'; } return $type; } function extension_exists($ext) { $ext = strtolower($ext); $loaded_extensions = get_loaded_extensions(); return in_array($ext, array_change_value_case($loaded_extensions, 0)); } function tag($tag, $attr = array(), $content = "") { $tag = "_" . $tag; $tagClass = array(); $tags = C('TPL_TAGS'); if (!empty($tags) && is_array($tags)) { foreach ($tags as $k) { $arr = explode('.', $k); if (import($k)) { $tagClass[] = array_pop($arr); } } } $tagClass[] = 'ViewTag'; foreach ($tagClass as $_class) { $obj = new $_class; if (method_exists($obj, $tag)) { return $obj->$tag($attr, $content); } } return false; } function safeFile($dirs) { $file = HDPHP_TPL . '/index.html'; foreach ($dirs as $d) { is_file($d . '/index.html') || copy($file, $d . '/index.html'); } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); class Cache { protected $isConnect = false; protected $options = array(); static public function init($options = array()) { return CacheFactory::factory($options); } public function __get($name) { return $this->get($name); } public function __set($name, $value) { return $this->set($name, $value); } public function __call($method, $args) { if (method_exists($this, $method)) { return call_user_func_array(array($this, $method), $args); } return false; } public function __unset($name) { return $this->del($name); } public function options($name, $value = null) { if (!is_null($value)) { $this->options[$name] = $value; return true; } else { if (isset($this->options[$name])) { return $this->options[$name]; } else { return null; } } } protected function queue($name) { static $drivers = array( "file" => "F" ); $driver = isset($this->options['Driver']) ? $this->options['Driver'] : 'file'; $_queue = $drivers[$driver][0]("hdphp_queue"); if (!$_queue) { $_queue = array(); } array_push($_queue, $name); $hdphp_queue = array_unique($_queue); if (count($hdphp_queue) > $this->options['length']) { $gc = array_shift($hdphp_queue); if ($gc) $this->del($gc); } return $drivers[$driver][0]("hdphp_queue", $hdphp_queue); } protected function record($type, $stat = 1) { if (!DEBUG && !C("SHOW_CACHE")) return; if ($type === 1) { $stat ? Debug::$cache['write_s']++ : Debug::$cache['write_f']++; } else { $stat ? Debug::$cache['read_s']++ : Debug::$cache['read_f']++; } } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); final class CacheFactory { public static $cacheFactory = null; protected $cacheList = array(); private function __construct() { } public static function factory($options) { $options = is_array($options) ? $options : array(); if (is_null(self::$cacheFactory)) { self::$cacheFactory = new cacheFactory(); } $driver = isset($options['driver']) ? $options['driver'] : C("CACHE_TYPE"); $driverName = md5_d($options); if (isset(self::$cacheFactory->cacheList[$driverName])) { return self::$cacheFactory->cacheList[$driverName]; } $class = 'Cache' . ucwords(strtolower($driver)); $classFile = HDPHP_DRIVER_PATH . 'Cache/' . $class . '.class.php'; if (!require_cache($classFile)) { throw_exception("缓存类型指定错误，不存在缓存驱动文件:" . $classFile); } $cacheObj = new $class($options); self::$cacheFactory->cacheList[$driverName] = $cacheObj; return self::$cacheFactory->cacheList[$driverName]; } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); class CacheFile extends Cache { public function __construct($options = array()) { $this->options['dir'] = isset($options['dir']) ? rtrim($options['dir'], '/') : CACHE_PATH; $this->options['expire'] = isset($options['expire']) ? intval($options['expire']) : C("CACHE_TIME"); $this->options['prefix'] = isset($options['prefix']) ? $options['prefix'] : ''; $this->options['length'] = isset($options['length']) ? $options['length'] : 0; $this->options['zip'] = isset($options['zip']) ? $options['zip'] : TRUE; $this->options['save'] = isset($options['save']) ? $options['save'] : true; $this->isConnect = is_dir($this->options['dir']) && is_writeable($this->options['dir']); if (!$this->isConnect) { $this->createDir(); } } private function createDir() { $this->isConnect = dir_create($this->options['dir']); } protected function getCacheFile($name) { return $this->options['dir'] . '/' . $this->options['prefix'] . md5($name) . ".php"; } public function set($name, $data, $expire = null) { $cacheFile = $this->getCacheFile($name); if (is_null($data)) { if (is_file($cacheFile)) { return unlink($cacheFile); } else { return true; } } $expire = sprintf("%010d", !is_null($expire) ? (int)$expire : $this->options['expire']); if (!$this->isConnect) { $this->createDir(); } $data = serialize($data); if ($this->options['zip'] && function_exists("gzcompress")) { $data = gzcompress($data, 6); } $data = "<?php\n//" . $expire . $data . "\n?>"; $stat = file_put_contents($cacheFile, $data); if ($stat) { if ($this->options['length'] > 0) { $this->queue($name); } $this->record(1,1); return true; } else { $this->record(1,0); return false; } } public function get($name, $ctime = null) { $cacheFile = $this->getCacheFile($name); if (!is_file($cacheFile)) { $this->record(2,0); return null; } $content = @file_get_contents($cacheFile); if (!$content) { $this->record(2,0); return null; } $expire = intval(substr($content, 8, 10)); $mtime = filemtime($cacheFile); if (is_int($ctime) && $mtime + $ctime < time()) { @unlink($cacheFile); $this->record(2,0); return false; } if ($expire > 0 && $mtime + $expire < time()) { @unlink($cacheFile); $this->record(2,0); return false; } $data = substr($content, 18, -3); if ($this->options['zip'] && function_exists("gzuncompress")) { $data = gzuncompress($data); } $this->record(2,1); return unserialize($data); } public function del($name) { $cacheFile = $this->getCacheFile($name); return is_file($cacheFile) && unlink($cacheFile); } public function delAll($time = null) { foreach (glob($this->options['dir'] . '/*.*') as $file) { if (is_file($file)) { if ($time) { (filemtime($file) + $time < time()) && unlink($file); } else { unlink($file); } } } return true; } }abstract class Db implements DbInterface { protected $table = null; public $field; public $fieldArr; public $lastQuery; public $pri = null; public $opt = array(); public $opt_old = array(); public $lastSql; public $error = NULL; protected $cacheTime; protected $dbPrefix; protected $condition = array( "eq" => " = ", "neq" => " <> ", "gt" => " > ", "egt" => " >= ", "lt" => " < ", "elt" => " <= ", ); public function connect($table) { if ($this->connectDb()) { if (!is_null($table)) { $this->dbPrefix = C("DB_PREFIX"); $this->table($table); $this->table = $table; $this->pri = $this->opt['pri']; $this->field = $this->opt['field']; $this->fieldArr = $this->opt['fieldArr']; $this->optInit(); } else { $this->optInit(); } return $this->link; } return false; } public function table($tableName) { if (is_null($tableName)) return; $this->optInit(); $field = $this->getFields($tableName); $this->opt['table'] = $tableName; $this->opt['pri'] = isset($field['pri']) && !empty($field['pri']) ? $field['pri'] : ''; $this->opt['field'] = '`' . implode('` , ' . '`', $field['field']) . '`'; $this->opt['fieldArr'] = $field['field']; } public function optInit() { $this->opt_old = $this->opt; $this->cacheTime = -1; $this->error = NULL; $opt = array( 'table' => $this->table, 'pri' => $this->pri, 'field' => "", 'fieldArr' => $this->fieldArr, 'where' => '', 'like' => '', 'group' => '', 'having' => '', 'order' => '', 'limit' => '', 'in' => '', 'cache' => '', 'filter_func' => array() ); $this->opt = array_merge($this->opt, $opt); } public function getFields($tableName) { $tableCache = $this->getCacheTable($tableName); $tableField = array(); foreach ($tableCache as $v) { $tableField['field'][] = $v['field']; if ($v['key']) { $tableField['pri'] = $v['field']; } } return $tableField; } private function getCacheTable($tableName) { if (!DEBUG) { $cacheTableField = F($tableName, false, TABLE_PATH); if ($cacheTableField) return $cacheTableField; } $tableinfo = $this->getTableFields($tableName); $fields = $tableinfo['fields']; if (!DEBUG) { F($tableName, $fields, TABLE_PATH); } return $fields; } private function getTableFields($tableName) { $sql = "show columns from " . $tableName; $fields = $this->query($sql); if ($fields === false) { error("表{$tableName}不存在", false); } $n_fields = array(); $f = array(); foreach ($fields as $res) { $f ['field'] = $res ['Field']; $f ['type'] = $res ['Type']; $f ['null'] = $res ['Null']; $f ['field'] = $res ['Field']; $f ['key'] = ($res ['Key'] == "PRI" && $res['Extra']) || $res ['Key'] == "PRI"; $f ['default'] = $res ['Default']; $f ['extra'] = $res ['Extra']; $n_fields [$res ['Field']] = $f; } $pri = ''; foreach ($n_fields as $v) { if ($v['key']) { $pri = $v['field']; } } $info = array(); $info['fields'] = $n_fields; $info['primarykey'] = $pri; return $info; } protected function debug($sql) { $this->lastSql = $sql; if (DEBUG && !preg_match("/^\s*show/i", $sql)) { Debug::$sqlExeArr[] = $sql; } } protected function error($error) { $this->error = $error; if (DEBUG) { error($this->error); } else { log_write($this->error); } } public function select($where) { if (empty($this->opt['table'])) { $this->error("没有可操作的数据表"); return false; } if (!empty($where)) { $this->where($where); } if (empty($this->opt['field'])) { $this->opt['field'] = "*"; } $chain = array("table", "group", "field", "order"); foreach ($chain as $v) { $this->opt[$v] = $this->addTableFix($this->opt[$v]); } $sql = "SELECT " . $this->opt['field'] . " FROM " . $this->opt['table'] . $this->opt['where'] . $this->opt['group'] . $this->opt['having'] . $this->opt['order'] . $this->opt['limit']; $data = $this->query($sql); return $data; } private function addTableFix($sql) { return preg_replace("@(\w+?\.[a-z]+?)@i", C("DB_PREFIX") . '\1', $sql); } public function insert($data, $type = "INSERT") { $value = $this->formatField($data); if (empty($value)) { $this->error("没有任何数据用于 INSERT"); return false; } else { $sql = $type . " INTO " . $this->opt['table'] . "(" . implode(',', $value['fields']) . ")" . "VALUES (" . implode(',', $value['values']) . ")"; return $this->exe($sql); } } public function formatField($vars) { $data = array(); foreach ($vars as $k => $v) { if (!$this->isField($k) || is_array($v)) { continue; } $data['fields'][] = "`" . $k . "`"; $v = $this->addslashes_d($v); $data['values'][] = is_numeric($v) ? $v : "\"" . $v . "\""; } return $data; } private function addslashes_d($v) { return get_magic_quotes_gpc() ? $v : addslashes_d($v); } public function update($data) { if (empty($this->opt['where'])) { if (isset($data[$this->opt['pri']])) { $this->opt['where'] = " WHERE " . $this->opt['pri'] . " = " . intval($data[$this->opt['pri']]); } else { $this->error('UPDATE更新语句必须输入条件'); return false; } } $data = $this->formatField($data); if (empty($data)) return false; $sql = "UPDATE " . $this->opt['table'] . " SET "; foreach ($data['fields'] as $n => $field) { $sql .= $field . "=" . $data['values'][$n] . ','; } $sql = trim($sql, ',') . $this->opt['where'] . $this->opt['limit']; return $this->exe($sql); } public function delete($data = array()) { $this->where($data); if (empty($this->opt['where'])) { $this->error("DELETE删除语句必须输入条件"); return false; } $sql = "DELETE FROM " . $this->opt['table'] . $this->opt['where'] . $this->opt['limit']; return $this->exe($sql); } private function statistics($type, $data) { $type = strtoupper($type); if (empty($data)) { $field = " {$type}(" . $this->opt['pri'] . ") AS " . $this->opt['pri']; } else if (is_string($data)) { $s = explode("|", $data); $field = " {$type}(" . $s[0] . ")"; $field .= isset($s[1]) ? ' AS ' . $s[1] : ''; } $this->opt['field'] = $field; } public function count($data) { $this->statistics(__FUNCTION__, $data); $result = $this->select(""); return is_array($result) && !empty($result) ? intval(current($result[0])) : NULL; } public function max($data) { $this->statistics(__FUNCTION__, $data); $result = $this->select(""); return is_array($result) && !empty($result) ? current($result[0]) : NULL; } public function min($data) { $this->statistics(__FUNCTION__, $data); $result = $this->select(""); return is_array($result) && !empty($result) ? current($result[0]) : NULL; } public function avg($data) { $this->statistics(__FUNCTION__, $data); $result = $this->select(""); return is_array($result) && !empty($result) ? current($result[0]) : NULL; } public function sum($data) { $this->statistics(__FUNCTION__, $data); $result = $this->select(""); return is_array($result) && !empty($result) ? current($result[0]) : NULL; } public function fieldFilter($opt) { if (empty($opt) || !is_array($opt)) return null; $field = array(); foreach ($opt as $k => $v) { if ($this->isField($k)) $field[$k] = $v; } return $field; } public function where($opt) { $where = ""; if (empty($opt)) { return false; } else if (is_numeric($opt)) { $where .= " " . $this->opt['pri'] . "=$opt "; } else if (is_string($opt)) { $where .= " $opt "; } else if (is_numeric(key($opt)) && is_numeric(current($opt))) { $where .= " " . $this->opt['pri'] . " IN(" . implode(",", $opt) . ")"; } else if (is_array($opt)) { foreach ($opt as $k => $v) { if (method_exists($this, $k)) { $this->$k($v); } else if (is_array($v)) { foreach ($v as $n => $m) { if (isset($this->condition[$n])) { $where .= " $k" . $this->condition[$n] . (is_numeric($m) ? $m : "'$m'"); } else if (in_array(strtoupper($m), array("OR", "AND"))) { if (preg_match("@(or|and)\s*$@i", $where)) { $where = substr($where, 0, -4); } $where .= strtoupper($m) . " "; } else { if (is_numeric($m)) { $where .= " $k in(" . implode(",", $v) . ") "; } else { $where .= " $k in('" . implode("','", $v) . "') "; } break; } if (!preg_match("@(or|and)\s*$@i", $where)) { $where .= " AND "; } } } else { if (is_numeric($k) && in_array(strtoupper($v), array("OR", "AND"))) { if (preg_match("@(or|and)\s*$@i", $where)) { $where = substr($where, 0, -4); } if (preg_match("@(or|and)\s*$@i", $where)) { $where = substr($where, 0, -4); } $where .= strtoupper($v) . " "; } else if (is_string($k) && !empty($v)) { $where .= (is_numeric($v) ? " $k=$v " : " $k='$v' ") . " AND "; } else if (is_numeric($k) && is_string($v)) { $where .= $v . " AND "; } else if (!empty($v) || $v === 0) { $where .= "'" . $v . "' AND "; } } } } $where = trim($where); if (!empty($where)) { if (empty($this->opt['where'])) { $this->opt['where'] = " WHERE $where"; } elseif (!preg_match("@^\s*(or|and)@i", $where)) { $this->opt['where'] .= " AND " . $where; } } $this->opt['where'] = preg_replace("@(or|and)\s*$@i", "", $this->opt['where']); } public function in($data) { $in = ''; if (!is_array($data)) { $in .= $this->opt['pri'] . " IN(" . $data . ") "; } else if (is_array($data) && !empty($data)) { if (is_string(key($data))) { $_v = current($data); if (!is_array($_v)) { $in .= "" . key($data) . " IN({$_v}) "; } else if (is_string($_v[0])) { $in .= " " . key($data) . " IN('" . implode("','", current($data)) . "') "; } else { $in .= " " . key($data) . " IN(" . implode(",", current($data)) . ") "; } } else { $in .= $this->opt['pri'] . " IN(" . implode(",", $data) . ") "; } } if (empty($this->opt['where'])) { $this->opt['where'] = " WHERE $in "; } else if (!preg_match("@^\s*(or|and)@i", $in)) { $this->opt['where'] .= " AND " . $in; } else { $this->opt['where'] .= "  " . $in; } } public function field($data) { if (is_string($data)) { $data = explode(",", $data); } $field = empty($this->opt['field']) ? "" : $this->opt['field'] . ','; foreach ($data as $d) { $a = explode("|", $d); $field .= trim($a[0]); $field .= isset($a[1]) ? ' AS ' . $a[1] . ',' : ','; } $this->opt['field'] = substr($field, 0, -1); } protected function isField($field) { return is_string($field) && in_array($field, $this->opt['fieldArr']); } public function limit($data) { $limit = ''; if (is_array($data)) { $limit .= implode(",", $data); } else { $limit .= $this->opt['limit'] . " $data "; } $this->opt['limit'] = " LIMIT $limit "; } public function order($data) { $order = ""; if (is_string($data)) { $order .= $data; } else if (is_array($data)) { foreach ($data as $f => $t) { $order .= " $f $t,"; } $order = substr($order, 0, -1); } if (empty($this->opt['order'])) { $this->opt['order'] = " ORDER BY $order "; } else { $this->opt['order'] .= "," . $order; } } public function group($opt) { $group = ""; if (is_string($opt)) { $group .= $opt; } else if (is_array($opt)) { $group .= implode(",", $opt); } if (empty($this->opt['group'])) { $this->opt['group'] = " GROUP BY $group"; } else { $this->opt['group'] .= ",$group "; } } public function having($opt) { $having = ""; if (is_string($opt)) { $having .= $opt; } if (empty($this->opt['having'])) { $this->opt['having'] = " HAVING $having"; } else if (!preg_match("@^\s*(or|and)@i", $having)) { $this->opt['having'] .= " AND " . $having; } else { $this->opt['having'] .= " " . $having; } } public function getLastSql() { return $this->lastSql; } public function getAllSql() { return Debug::$sqlExeArr; } public function cache($time = -1) { $this->cacheTime = is_numeric($time) ? $time : -1; } public function getTableInfo($table) { $table = empty($table) ? null : $table; $info = $this->query("SHOW TABLE STATUS FROM " . C("DB_DATABASE")); $arr = array(); $arr['total_size'] = 0; $arr['total_row'] = 0; foreach ($info as $k => $t) { if ($table) { if (!in_array($t['Name'], $table)) { continue; } } $arr['table'][$t['Name']]['tablename'] = $t['Name']; $arr['table'][$t['Name']]['engine'] = $t['Engine']; $arr['table'][$t['Name']]['rows'] = $t['Rows']; $arr['table'][$t['Name']]['collation'] = $t['Collation']; $charset = $arr['table'][$t['Name']]['collation'] = $t['Collation']; $charset = explode("_", $charset); $arr['table'][$t['Name']]['charset'] = $charset[0]; $arr['table'][$t['Name']]['datafree'] = $t['Data_free']; $arr['table'][$t['Name']]['size'] = $t['Data_free'] + $t['Data_length']; $info = $this->getTableFields($t['Name']); $arr['table'][$t['Name']]['field'] = $info['fields']; $arr['table'][$t['Name']]['primarykey'] = $info['primarykey']; $arr['table'][$t['Name']]['autoincrement'] = $t['Auto_increment'] ? $t['Auto_increment'] : ''; $arr['total_size'] += $arr['table'][$t['Name']]['size']; $arr['total_row']++; } return empty($arr) ? false : $arr; } public function getSize($table) { $table = empty($table) ? null : $table; $sql = "show table status from " . C("DB_DATABASE"); $row = $this->query($sql); $size = 0; foreach ($row as $v) { if ($table) { $size += in_array(strtolower($v['Name']), $table) ? $v['Data_length'] + $v['Index_length'] : 0; } else { $size += $v['Data_length'] + $v['Index_length']; } } return get_size($size); } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); final class DbFactory { public static $dbFactory = null; protected $driverList = array(); private function __construct() { } public static function factory($driver = null, $tableName = null) { if (is_null(self::$dbFactory)) { self::$dbFactory = new dbFactory(); } if (is_null($driver)) { $driver = ucfirst(strtolower(C("DB_DRIVER"))); } if (is_null($tableName)) { $tableName = 'empty'; } if (isset(self::$dbFactory->driverList[$tableName]) && self::$dbFactory->driverList[$tableName]->link) { return self::$dbFactory->driverList[$tableName]; } if (self::$dbFactory->getDriver($driver, $tableName)) { return self::$dbFactory->driverList[$tableName]; } else { return false; } } private function getDriver($driver, $tableName) { $class = "Db" . $driver; $classFile = HDPHP_DRIVER_PATH . 'Db/Driver/' . $class . '.Tool.php'; require_cache($classFile); $this->driverList[$tableName] = new $class; $table = $tableName == 'empty' ? null : $tableName; return $this->driverList[$tableName]->connect($table); } private function close() { foreach ($this->driverList as $db) { $db->close(); } } function __destruct() { $this->close(); } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); interface DbInterface { public function connectDb(); public function close(); public function exe($sql); public function query($sql); public function getInsertId(); public function getAffectedRows(); public function getVersion(); public function beginTrans(); public function commit(); public function rollback(); }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); class Model { public $tableFull = null; public $table = null; public $default = array(); public $trigger = TRUE; public $join = array(); public $view = array(); public $joinTable = array(); public $result = NULL; public $db = null; public $data = array(); public $validate = array(); public $auto = array(); public $error = null; public $map = array(); public function __construct($table = null, $full = null, $driver = null) { if (method_exists($this, "__init")) { $this->__init(); } $this->run($table, $full, $driver); } protected function init() { $opt = array( "trigger" => true, "joinTable" => array(), "result" => NULL, "data" => array(), "error" => "" ); foreach ($opt as $n => $v) { $this->$n = $v; } } protected function run($table, $full = null, $driver = null) { $this->getTable($table, $full); $db = DbFactory::factory($driver, $this->tableFull); if ($db) { $this->db = $db; } else { if (DEBUG) { error(mysqli_connect_error() . "数据库连接出错了请检查配置文件中的参数", false); } else { log_write("数据库连接出错了请检查配置文件中的参数"); } } $vars = get_object_vars($this); unset($vars['default']); $this->default = $vars; } protected function getTable($table = null, $full = FALSE) { if (!is_null($this->tableFull)) { $table = $this->tableFull; } elseif (!is_null($this->table)) { $table = C("DB_PREFIX") . $this->table; } else if (is_null($table)) { $table = null; } elseif (!is_null($table)) { if ($full == true) { $table = $table; } else { $table = C("DB_PREFIX") . $table; } } else { $table = C("DB_PREFIX") . CONTROL; } $this->tableFull = $table; $this->table = preg_replace('@^\s*' . C("DB_PREFIX") . '@', '', $table); } public function __set($var, $value) { $_var = strtolower($var); $property = array_keys($this->db->opt); if (in_array($_var, $property)) { $this->$_var($value); } else { $this->data[$var] = $value; } } public function __get($name) { return isset($this->data[$name]) ? $this->data[$name] : null; } public function data($data = array()) { if (is_array($data) && !empty($data)) { $this->data = $data; } else if (empty($this->data)) { $this->data = $_POST; } return $this; } public function create($data = array()) { if (!$this->tokenCheck()) { return false; } $this->data($data); $this->fieldMap(); if ($this->validate()) { $this->auto(); return true; } return false; } protected function getCurrentMethod() { return isset($this->data[$this->db->pri]) ? 2 : 1; } public function join($table = null) { if (is_null($table)) { $this->joinTable = NULL; } else if (!empty($table) && is_string($table)) { $this->joinTable = explode(",", $table); } return $this; } public function trigger($open = FALSE) { $this->trigger = $open; return $this; } public function validate($data = array()) { $this->data($data); if (!is_array($this->data) || empty($this->data)) return false; $current_method = $this->getCurrentMethod(); $_data = & $this->data; if (!is_array($this->validate) || empty($this->validate)) { return true; } foreach ($this->validate as $v) { $name = $v[0]; $action = isset($v[4]) ? $v[4] : 3; if (!in_array($action, array($current_method, 3))) { continue; } $condition = isset($v[3]) ? $v[3] : 1; $msg = $v[2]; switch ($condition) { case 1: if (!isset($_data[$name])) { continue 2; } break; case 2: if (!isset($_data[$name])) { $this->error = $msg; return false; } break; case 3: if (!isset($_data[$name]) || empty($_data[$name])) { continue 2; } break; } $method = explode(":", $v[1]); $func = $method[0]; $args = isset($method[1]) ? str_replace(" ", '', $method[1]) : ''; if (method_exists($this, $func)) { $res = call_user_func_array(array($this, $func), array($name, $_data[$name], $msg, $args)); if ($res === true) { continue; } $this->error = $res; return false; } else if (function_exists($func)) { $res = $func($name, $_data[$name], $msg, $args); if ($res === true) { continue; } $this->error = $res; return false; } else { $validate = new Validate(); $func = '_' . $func; if (method_exists($validate, $func)) { $res = call_user_func_array(array($validate, $func), array($name, $_data[$name], $msg, $args)); if ($res === true) { continue; } $this->error = $res; return false; } } } return true; } public function auto($data = array()) { $this->data($data); $_data = & $this->data; $motion = $this->getCurrentMethod(); foreach ($this->auto as $v) { $name = $v[0]; $action = $v[1]; $condition = isset($v[2]) ? $v[2] : 1; switch ($condition) { case 1: if (!isset($_data[$name])) { continue 2; } break; case 2: break; case 3: if (!isset($_data[$name]) || empty($_data[$name])) { unset($_data[$name]); continue 2; } break; } $type = isset($v[3]) ? $v[3] : 3; $handle = isset($v[4]) ? $v[4] : "string"; if ($motion != $type && $type != 3) { continue; } $_data[$name] = isset($_data[$name]) ? $_data[$name] : NULL; switch (strtolower($handle)) { case "function": if (function_exists($action)) { $_data[$name] = $action($_data[$name]); } break; case "method": if (method_exists($this, $action)) { $_data[$name] = call_user_func_array(array($this, $action), array($_data[$name])); } break; case "string": $_data[$name] = $action; break; } } } protected function fieldMap() { if (empty($this->map)) return; $this->data(); foreach ($this->map as $k => $v) { if (isset($this->data[$k])) { $this->data[$v] = $this->data[$k]; unset($this->data[$k]); } } } public function __call($func, $args) { error(L("model__call_error") . $func, false); } public function table($table, $full = FALSE) { if ($full !== TRUE) { $table = C("DB_PREFIX") . $table; } $this->db->table($table); $this->join(NULL); return $this; } public function field($field = array(), $check = true) { if (empty($field)) return $this; $this->db->field($field, $check); return $this; } public function cache($time = -1) { $this->db->cache($time); return $this; } public function like() { $args = func_get_args(); $this->db->like($args); return $this; } public function group($arg = array()) { if (empty($arg)) return $this; $this->db->group($arg); return $this; } public function having($arg = array()) { if (empty($arg)) return $this; $this->db->having($arg); return $this; } public function order($arg = array()) { if (empty($arg)) return $this; $this->db->order($arg); return $this; } public function limit($start = null, $end = null) { if (is_null($start)) return $this; if (is_array($start)) { $limit = $start; } else if (!is_null($end)) { $limit = $start . "," . $end; } else { $limit = $start; } $this->db->limit($limit); return $this; } public function in($arg = array()) { if (empty($arg)) return $this; $this->db->in($arg); return $this; } public function del($data = array()) { return $this->delete($data); } public function delAll($data = array()) { $this->where("1=1"); return $this->delete($data); } public function delete($data = array()) { $this->trigger and $this->__before_del(); $result = $this->db->delete($data); $this->result = $result; $this->error = $this->db->error; $this->trigger and $this->__after_del(); $this->init(); return $result; } public function query($data = array()) { return $this->db->query($data); } public function exe($sql) { $stat = $this->db->exe($sql); $this->init(); return $stat; } public function find($data = array()) { $this->limit(1); $result = $this->select($data); return is_array($result) && isset($result[0]) ? $result[0] : $result; } public function one($data = array()) { return $this->find($data); } public function findAll($args = array()) { return $this->select($args); } public function all($args = array()) { return $this->select($args); } public function select($args = array()) { $this->trigger and $this->__before_select(); $result = $this->db->select($args); $this->result = $result; $this->trigger and $this->__after_select(); $this->error = $this->db->error; $this->init(); return $result; } public function where($data = array()) { if (!empty($data)) { $this->db->where($data); } return $this; } public function getField($field, $return_all = false) { $this->field($field); $result = $this->select(); if (is_array($result) && !empty($result) && $return_all === false) { if (count($result[0]) == 1) { return current($result[0]); } else { $k = key($result[0]); return array($k => $result[0]); } } else { return $result; } } public function update($data = array()) { $this->data($data); $this->trigger and $this->__before_update(); $data = $this->data; if (empty($data)) { $this->error = "没有任何数据用于UPDATE！"; $this->init(); return false; } $this->error = $this->db->error; $result = $this->db->update($data); $this->result = $result; $this->trigger and $this->__after_update(); $this->init(); return $result; } public function save($data = array()) { return $this->update($data); } public function insert($data = array(), $type = "INSERT") { $this->data($data); $this->trigger and $this->__before_add(); $data = $this->data; if (empty($data)) { $this->error = "没有任何数据用于INSERT！"; $this->init(); return false; } $result = $this->db->insert($data, $type); $this->result = $result; $this->error = $this->db->error; $this->trigger and $this->__after_add(); $this->init(); return $result; } public function replace($data = array()) { return $this->insert($data, "REPLACE"); } public function add($data = array()) { return $this->insert($data); } public function fieldExists($fieldName, $table) { $sql = "DESC " . C("DB_PREFIX") . $table; $field = $this->query($sql); foreach ($field as $f) { if ($f['Field'] == $fieldName) { return true; } } return false; } public function count($args = array()) { $result = $this->db->count($args); $this->init(); return $result; } public function max($args = array()) { $result = $this->db->max($args); $this->init(); return $result; } public function min($args = array()) { $result = $this->db->min($args); $this->init(); return $result; } public function avg($args = array()) { $result = $this->db->avg($args); $this->init(); return $result; } public function sum($args = array()) { $result = $this->db->sum($args); $this->init(); return $result; } public function inc($field, $where, $step = 1) { $sql = "UPDATE " . $this->db->opt['table'] . " SET " . $field . '=' . $field . '+' . $step . " WHERE " . $where; return $this->exe($sql); } public function fieldFilter($data = array()) { $this->data($data); $data = $this->data; $data = $data ? $data : $_GET; return $this->db->fieldFilter($data); } public function dec($field, $where, $step = 1) { $sql = "UPDATE " . $this->db->opt['table'] . " SET " . $field . '=' . $field . '-' . $step . " WHERE " . $where; return $this->exe($sql); } public function tokenCheck() { if (C("TOKEN_ON") || isset($_POST[C("TOKEN_NAME")]) || isset($_GET[C("TOKEN_NAME")])) { if (!Token::check()) { $this->error = L("model_token_error"); return false; } } return true; } public function getAffectedRows() { return $this->db->getAffectedRows(); } public function getInsertId() { return $this->db->getInsertId(); } public function getLastSql() { return $this->db->getLastSql(); } public function getAllSql() { return $this->db->getAllSql(); } public function getVersion() { return $this->db->getVersion(); } public function createDatabase($database, $charset = "utf8") { return $this->exe("CREATE DATABASE IF NOT EXISTS `$database` CHARSET " . $charset); } public function getSize($table = "") { return $this->db->getSize($table); } public function getTableInfo($table = array()) { return $this->db->getTableInfo($table); } public function truncate($table) { if (is_array($table) && !empty($table)) { foreach ($table as $t) { $this->exe("TRUNCATE TABLE `" . $t . "`"); } return true; } } public function optimize($table) { if (is_array($table) && !empty($table)) { foreach ($table as $t) { $this->exe("OPTIMIZE TABLE `" . $t . "`"); } return true; } } public function repair($table) { if (is_array($table) && !empty($table)) { foreach ($table as $t) { $this->exe("REPAIR TABLE `" . $t . "`"); } return true; } } public function dropTable($table) { if (is_array($table) && !empty($table)) { foreach ($table as $t) { $this->exe("DROP TABLE IF EXISTS `" . $t . "`"); } } return true; } public function rename($old, $new) { $this->exe("ALTER TABLE `" . $old . "` RENAME " . $new); } public function beginTrans($stat = true) { return $this->db->beginTrans($stat); } public function runSql($str) { $str = str_replace("\r", "\n", $str); $sqlArr = explode(";\n", trim($str)); $sql = array(); $num = 0; foreach ($sqlArr as $s) { $query = explode("\n", trim($s)); $sql[$num] = ''; foreach ($query as $q) { $sql[$num] .= $q[0] == '#' || $q[0] . $q[1] == '--' ? '' : $q; } $num++; } foreach ($sql as $s) { $this->exe($s); } return true; } public function commit() { return $this->db->commit(); } public function rollback() { return $this->db->rollback(); } public function __before_add() { } public function __after_add() { } public function __before_del() { } public function __after_del() { } public function __before_update() { } public function __after_update() { } public function __before_select() { } public function __after_select() { } }defined("HAS_ONE") or define("HAS_ONE", "HAS_ONE"); defined("HAS_MANY") or define("HAS_MANY", "HAS_MANY"); defined("BELONGS_TO") or define("BELONGS_TO", "BELONGS_TO"); defined("MANY_TO_MANY") or define("MANY_TO_MANY", "MANY_TO_MANY"); class RelationModel extends Model { public $join = array(); private function check_join($table) { if (!empty($this->joinTable) && !in_array($table, $this->joinTable)) { return false; } else { return true; } } private function checkJoinSet($set) { if (empty($set['type']) || !in_array($set['type'], array(HAS_ONE, HAS_MANY, BELONGS_TO, MANY_TO_MANY)) ) { error("关联定义规则[type]设置错误"); return false; } if (empty($set['foreign_key'])) { error("关联定义规则[foreign_key]设置错误"); return false; } if (empty($set['parent_key'])) { error("关联定义规则[parent_key]设置错误"); return false; } return true; } public function select($data = array()) { $pri = $this->db->pri; $result = call_user_func(array($this->db, __FUNCTION__), $data); if (!$result || is_null($this->joinTable) || empty($this->join) || !is_array($this->join)) { $this->error = $this->db->error; $this->result = $result; $this->trigger and $this->__before_select(); $this->init(); return $result; } $this->result =& $result; foreach ($this->join as $table => $set) { if (!$this->check_join($table)) continue; if (!$this->checkJoinSet($set)) continue; $fk = $set['foreign_key']; $pk = $set['parent_key']; $db = M($table); $field = ""; if (isset($set['field'])) { $field = $set['field']; } switch ($set['type']) { case HAS_ONE: foreach ($result as $n => $d) { $s = $db->field($field)->where($fk . '=' . $d[$pri])->find(); if (is_array($s)) { $result[$n] = array_merge($d, $s); } } break; case HAS_MANY: foreach ($result as $n => $d) { $s = $db->field($field)->where($fk . '=' . $d[$pri])->all(); if (is_array($s)) { $result[$n][$table] = $s; } } break; case BELONGS_TO: foreach ($result as $n => $d) { $s = $db->field($field)->where($pk . '=' . $d[$fk])->find(); if (is_array($s)) { $result[$n] = array_merge($d, $s); } } break; case MANY_TO_MANY: if (!isset($set['relation_table'])) break; foreach ($result as $n => $d) { $s = $db->table($set['relation_table'])->field($fk)->where($pk . '=' . $d[$pri])->all(); if (is_array($s)) { $_id = array(); foreach ($s as $_s) { $_id[] = $_s[$fk]; } $result[$n][$table] = $db->table($table)->in($_id)->all(); } } break; } } $this->error = $this->db->error; $this->trigger and $this->__after_select(); $data = empty($result) ? null : $result; $this->init(); return $data; } public function insert($data = array(), $type = "INSERT") { $this->data($data); $this->trigger and $this->__before_add(); $data = $this->data; if (empty($data)) { $this->error = "没有任何数据用于INSERT！"; $this->trigger and $this->__after_add(); $this->init(); return false; } $id = call_user_func(array($this->db, __FUNCTION__), $data, $type); if (!$id || is_null($this->joinTable) || empty($this->join) || !is_array($this->join)) { $this->error = $this->db->error; $this->result = $id; $this->trigger and $this->__after_add(); $this->init(); return $id; } $this->result = array(); $result_id = & $this->result; $result_id[$this->table] = $id; foreach ($this->join as $table => $set) { if (empty($data[$table]) || !is_array($data[$table])) continue; if (!$this->check_join($table)) continue; if (!$this->checkJoinSet($set)) continue; $fk = $set['foreign_key']; $pk = $set['parent_key']; $db = M($table); switch ($set['type']) { case HAS_ONE: $data[$table][$fk] = $id; $result_id[$table] = $db->insert($data[$table], $type); break; case HAS_MANY: $result_id[$table] = array(); foreach ($data[$table] as $d) { if (is_array($d)) { $d[$fk] = $id; $result_id[$table][] = $db->insert($d, $type); } } break; case BELONGS_TO: $_id = $db->add($data[$table]); $db->table($this->table)->where("id=" . $id)->save(array($fk => $_id)); $result_id[$table] = $_id; break; case MANY_TO_MANY: if (!isset($set['relation_table'])) break; $_id = $db->add($data[$table]); $result_id[$table] = $_id; $_r_id = $db->table($set['relation_table'])->insert(array($pk => $id, $fk => $_id), $type); $result_id[$set['relation_table']] = $_r_id; } } $this->error = $this->db->error; $result = empty($result_id) ? null : $result_id; $this->trigger and $this->__after_add(); $this->init(); return $result; } public function update($data = array()) { $this->data($data); $this->trigger and $this->__before_update(); $data = $this->data; if (empty($data)) { $this->error = "没有任何数据用于UPDATE！"; $this->__after_update(); $this->init(); return false; } $stat = call_user_func(array($this->db, __FUNCTION__), $data); if (!$stat || is_null($this->joinTable) || empty($this->join) || !is_array($this->join)) { $this->error = $this->db->error; $this->result = $stat; $this->trigger and $this->__after_update(); $this->init(); return $stat; } $pri = $this->db->pri; $where = preg_replace('@\s*WHERE@i', '', $this->db->opt_old['where']); $_p = M($this->table)->field($pri)->where($where)->find(); $id = $_p[$pri]; $this->result = array(); $result_id = & $this->result; $result_id = array(); $result_id[$this->table] = $stat; foreach ($this->join as $table => $set) { if (empty($data[$table]) || !is_array($data[$table])) continue; if (!$this->check_join($table)) continue; if (!$this->checkJoinSet($set)) continue; $fk = $set['foreign_key']; $pk = $set['parent_key']; $db = M($table); switch ($set['type']) { case HAS_ONE: $data[$table][$fk] = $id; $db->where("$fk=$id")->save($data[$table]); break; case HAS_MANY: $db->where($fk . '=' . $id)->del(); foreach ($data[$table] as $d) { if (is_array($d)) { $d[$fk] = $id; $db->replace($d); } } break; CASE BELONGS_TO: $temp = $db->table($this->table)->find($id); $data[$table][$pk] = $temp[$fk]; $result_id[$table] = $db->save($data[$table]); break; case MANY_TO_MANY: if (!isset($set['relation_table'])) break; $result_id[$table] = $db->save($data[$table]); break; } } $this->error = $this->db->error; $result = empty($result_id) ? null : $result_id; $this->__after_update(); $this->init(); return $result; } public function delete($data = array()) { $this->trigger and $this->__before_del(); $id = M($this->table)->where($data)->select(); if (!$id) { $this->error = $this->db->error; $this->trigger and $this->__after_del(); $this->init(); return true; } $this->db->opt = $this->db->opt_old; $stat = call_user_func(array($this->db, __FUNCTION__)); if (!$stat || is_null($this->joinTable) || empty($this->join) || !is_array($this->join)) { $this->error = $this->db->error; $this->result = $stat; $this->trigger and $this->__after_del(); $this->init(); return $stat; } $pri = $this->db->pri; $this->result = array(); $result_id =& $this->result; $result_id[$this->table] = $stat; foreach ($this->join as $table => $set) { if (!$this->check_join($table)) continue; if (!$this->checkJoinSet($set)) continue; $fk = $set['foreign_key']; $pk = $set['parent_key']; $db = M($table); switch ($set['type']) { case HAS_ONE: case HAS_MANY: foreach ($id as $p) { $result_id[$table] = $db->where($fk . '=' . $p[$pk])->delete(); } break; CASE BELONGS_TO: break; case MANY_TO_MANY: break; } } $this->error = $this->db->error; $result = empty($result_id) ? null : $result_id; $this->trigger and $this->__after_del(); $this->init(); return $result; } }defined("INNER_JOIN") or define("INNER_JOIN", "INNER JOIN"); defined("LEFT_JOIN") or define("LEFT_JOIN", "LEFT JOIN"); defined("RIGHT_JOIN") or define("RIGHT_JOIN", "RIGHT JOIN"); class ViewModel extends Model { public $view = array(); private function check_join($table) { if (is_null($this->joinTable)) { return false; } else if (is_array($this->joinTable) && !empty($this->joinTable) && !in_array($table, $this->joinTable)) { return false; } else { return true; } } private function checkViewSet($set) { if (empty($set['type']) || !in_array($set['type'], array(INNER_JOIN, LEFT_JOIN, RIGHT_JOIN)) ) { error("关联定义规则[type]设置错误"); return false; } if (empty($set['on'])) { error("关联定义规则[on]设置错误"); return false; } return true; } protected function init() { $opt = array( "trigger" => true, "joinTable" => array(), "result" => NULL, "data" => array(), "error" => "" ); foreach ($opt as $n => $v) { $this->$n = $v; } } public function setJoinTable() { if (is_null($this->joinTable) || empty($this->view)) { return; } $field = $this->db->opt['field']; if (empty($field)) { $field = "*"; } $from = " " . $this->tableFull . " "; foreach ($this->view as $table => $set) { if (!$this->check_join($table)) continue; if (!$this->checkViewSet($set)) continue; $_table = C("DB_PREFIX") . $table; $from .= $set['type'] . " " . $_table . " "; $from .= " ON " . $set['on'] . " "; } $this->db->opt['field'] = $field; $this->db->opt['table'] = $from; } public function select($data = array()) { $this->setJoinTable($data); return parent::select($data); } public function count($args = "") { $this->setJoinTable(); return parent::count($args); } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); abstract class SessionAbstract { abstract function open(); abstract function read($sid); abstract function write($sid, $data); abstract function destroy($sid); abstract function gc(); protected $sessionName; protected $sessionLifeTime; protected $sessionGcDivisor; protected $card; public function __construct() { $this->init(); } public function init() { if (!ini_get("Session.auto_start")) { @ini_set('Session.use_trans_sid', 0); @ini_set('Session.auto_start', 0); @ini_set('Session.use_cookies', 1); @ini_set('Session.gc_maxlifetime', (int)C("SESSION_LIFETIME")); @ini_set('Session.gc_divisor', (int)C("SESSION_GC_DIVISOR")); } $this->setSessionName(); $this->setSessionId(); $this->sessionLifeTime = (int)C("SESSION_LIFETIME"); $this->sessionGcDivisor = (int)C("SESSION_GC_DIVISOR"); $this->card = md5($_SERVER['REMOTE_ADDR'] . (isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "")); session_set_save_handler( array($this, "open"), array($this, "close"), array($this, "read"), array($this, "write"), array($this, "destroy"), array($this, "gc") ); } protected function setSessionName() { $this->sessionName = C("SESSION_NAME") ? C("SESSION_NAME") : session_name(); session_name(C("SESSION_NAME")); } protected function setSessionId() { if (isset($_GET[$this->sessionName])) { session_id($_GET[$this->sessionName]); } elseif (isset($_POST[$this->sessionName])) { session_id($_POST[$this->sessionName]); } } public function close() { if (mt_rand(1, $this->sessionGcDivisor) == 1) { $this->gc(); } return true; } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); final class SessionFactory { public static $sessionFactory = null; protected $driver = array(); private function __construct() { } public static function factory() { if (is_null(self::$sessionFactory)) { self::$sessionFactory = new sessionFactory(); } $driver = ucfirst(strtolower(C("SESSION_ENGINE"))); if (isset(self::$sessionFactory->driver[$driver])) { return self::$sessionFactory->driver[$driver]; } self::$sessionFactory->getDriver($driver); return self::$sessionFactory->driver[$driver]; } private function getDriver($driver) { $class = 'Session'.ucfirst($driver); $this->driver[$driver] = new $class; } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); class SessionFile extends SessionAbstract { public function run() { if (C("SESSION_SAVE_PATH")) { session_save_path(C("SESSION_SAVE_PATH")); } if (!session_save_path()) { dir::create(TEMP_ . '/session'); session_save_path(ROOT_PATH . '/session'); } session_name(C("SESSION_NAME")); session_set_save_handler( array(&$this, "open"), array(&$this, "close"), array(&$this, "read"), array(&$this, "write"), array(&$this, "destroy"), array(&$this, "gc") ); } public function open() { return true; } public function read($sid) { $session = session_save_path() . '/hdsess_' . $sid; if (!is_file($session)) { return false; } return file_get_contents($session); } public function write($sid, $data) { $session = session_save_path() . '/hdsess_' . $sid; return file_put_contents($session, $data) ? true : false; } public function destroy($sid) { $session = session_save_path() . '/hdsess_' . $sid; if (is_file($session)) { unlink($session); } } public function gc() { $path = session_save_path(); foreach (glob($path . "/*") as $file) { if (strpos($file, "hdsess_") === false) continue; if (filemtime($file) + C("SESSION_LIFETIME") < time()) { unlink($file); } } return true; } public function close() { if (mt_rand(1, C("SESSION_GC_DIVISOR")) == 1) { $this->gc(); } return true; } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); final class ViewHd extends View { public $vars = array(); public $const = array(); public $tplFile; public $compileFile; public function display($tplFile = null, $cacheTime = null, $cachePath = null, $contentType = "text/html", $charset = "", $show = true) { $this->tplFile = $this->getTemplateFile($tplFile); if (!$this->tplFile) return; $this->compileFile = COMPILE_PATH . basename($this->tplFile, C("TPL_FIX")) . '_' . substr(md5(APP . CONTROL . METHOD), 0, 5) . '.php'; if (DEBUG) { Debug::$tpl[] = array(basename($this->tplFile), $this->compileFile); } $cacheTime = is_int($cacheTime) ? $cacheTime : intval(C("CACHE_TPL_TIME")); $content = false; $cachePath = $cachePath ? $cachePath : CACHE_PATH; if ($cacheTime >= 0) { $content = S($_SERVER['REQUEST_URI'], false, $cacheTime, array("dir" => $cachePath, "Driver" => "File")); } if (!$content) { if ($this->compileInvalid($tplFile)) { $this->compile(); } $_CONFIG = C(); $_LANGUAGE = L(); if (!empty($this->vars)) { extract($this->vars); } ob_start(); include($this->compileFile); $content = ob_get_clean(); if ($cacheTime >= 0) { is_dir(CACHE_PATH) || dir_create(CACHE_PATH); S($_SERVER['REQUEST_URI'], $content, $cacheTime, array("dir" => $cachePath, "Driver" => "File")); } } if ($show) { $charset = strtoupper(C("CHARSET")) == 'UTF8' ? "UTF-8" : strtoupper(C("CHARSET")); if (!headers_sent()) { header("Content-type:" . $contentType . ';charset=' . $charset); } echo $content; } else { return $content; } } public function fetch($tplFile = null, $cacheTime = null, $cachePath = null, $contentType = "text/html", $charset = "") { return $this->display($tplFile, $cacheTime, $cachePath, $contentType, $charset, false); } public function isCache($cachePath = null) { $cachePath = $cachePath ? $cachePath : CACHE_PATH; return S($_SERVER['REQUEST_URI'], false, null, array("dir" => $cachePath, "Driver" => "File")) ? true : false; } private function compileInvalid() { $tplFile = $this->tplFile; $compileFile = $this->compileFile; return DEBUG || CLEAR_TPL_COMPILE_FILE || !file_exists($compileFile) || (filemtime($tplFile) > filemtime($compileFile)); } public function compile() { if (!$this->compileInvalid()) return; $compileObj = new ViewCompile($this); $compileObj->run(); } public function getCompileContent() { return file_get_contents($this->compileFile); } public function assign($var, $value) { return $this->vars[$var] = $value; } function __set($name, $value) { if (isset($this->vars[$name])) { $this->vars[$name] = $value; } } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); abstract class View { protected function getTemplateFile($tplFile) { if (is_null($tplFile)) { $tplFile = METHOD . C("TPL_FIX"); } else { if (count(explode("/", $tplFile)) > 2) { if (!preg_match('@\.[a-z]{3,4}$@i', $tplFile)) { $tplFile .= C("TPL_FIX"); } if (!is_file($tplFile)) { DEBUG and error(L("view_getTemplateFile_error3") . $tplFile); } return $tplFile; } $tplFile = str_replace(C("TPL_FIX"), '', $tplFile) . C("TPL_FIX"); } if (strstr(C("TPL_DIR"), '/') && !strstr($tplFile, '/')) { $tplFile = TPL_PATH . $tplFile; } else { $fileArr = explode("/", $tplFile); $file = array_pop($fileArr); switch (count($fileArr)) { case 0: $tplFile = TPL_PATH . CONTROL . '/' . $tplFile; break; case 1: $tplFile = TPL_PATH . $fileArr[0] . '/' . $file; break; case 2: $tplFile = str_replace(APP, $fileArr[0], TPL_PATH) . '/' . $fileArr[1] . '/' . $file; break; } } if (!is_file($tplFile)) { halt(L("view_getTemplateFile_error3") . $tplFile); } return $tplFile; } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); final class ViewFactory { public static $viewFactory = ''; protected $driverList = array(); private function __construct() { } public static function factory($driver = null) { if (self::$viewFactory == '') { self::$viewFactory = new viewFactory(); } if (is_null($driver)) { $driver = ucfirst(strtolower(C("TPL_ENGINE"))); } if (isset(self::$viewFactory->driverList[$driver])) { return self::$viewFactory->driverList[$driver]; } self::$viewFactory->getDriver($driver); return self::$viewFactory->driverList[$driver]; } public function getDriver($driver) { if (isset($this->driverList[$driver])) { return $this->driverList[$driver]; } $class = "View" . ucfirst($driver); import($class, HDPHP_DRIVER_PATH . 'View/'); $this->driverList[$driver] = new $class(); return true; } }if (!defined("HDPHP_PATH")) exit('No direct script access allowed'); class ViewCompile { public $view; public $content; private $left; private $right; private $condition = array( "\s+neq\s+" => " <> ", "\s+eq\s+" => " == ", "\s+gt\s+" => " > ", "\s+egt\s+" => " >= ", "\s+lt\s+" => " < ", "\s+elt\s+" => " <= " ); private $functionAlias = array( "default" => "_default" ); function __construct(&$view = null) { $this->left = C("TPL_TAG_LEFT"); $this->right = C("TPL_TAG_RIGHT"); $this->view = $view; } public function run() { $this->content = file_get_contents($this->view->tplFile); $this->loadParseTags(); $this->replaceGlobalFunc(); $this->compile(); $this->parseTokey(); $this->replaceConst(); $this->content = '<?php if(!defined("HDPHP_PATH"))exit;C("DEBUG_SHOW",false);?>' . $this->content; if (!is_dir(COMPILE_PATH)) { Dir::create(COMPILE_PATH); copy(HDPHP_TPL_PATH . 'index.html', COMPILE_PATH . 'index.html'); } file_put_contents($this->view->compileFile, $this->content); $safeFile = dirname($this->view->compileFile) . "/index.html"; is_file($safeFile) or Dir::safeFile(dirname($safeFile)); } private function replaceLangConfig($content) { $preg = array( '/\$hd.config\.(\w+)\s*/is', '/\$hd.language\.(\w+)\s*/is' ); $replace = array( 'C("\1")', 'L("\1")' ); return preg_replace($preg, $replace, $content); } private function replaceGlobalFunc() { $this->content = preg_replace('/\{\|(\w+):(.*?)\}/i', '<?php echo \1(\2);?>', $this->content); $this->content = preg_replace('/\{\|(\w+)\((.*?)\}/i', '<?php echo \1(\2;?>', $this->content); } private function loadParseTags() { $tagClass = array(); $tags = C('TPL_TAGS'); if (!empty($tags) && is_array($tags)) { foreach ($tags as $k) { $arr = explode('.', $k); if (import($k)) { $tagClass[] = array_pop($arr); } } } if (import('HDPHP.Lib.Driver.View.ViewTag')) { $tagClass[] = 'ViewTag'; $this->parseTagClass($tagClass); } } private function parseTagClass($tagClass) { foreach ($tagClass as $class) { $tagObj = new $class(); $tagMethod = get_class_methods($class); foreach ($tagMethod as $tagName) { $block = 1; $level = 1; $tagName = substr($tagName, 1); if (isset($tagObj->tag)) { $tagSet = $tagObj->tag; $block = isset($tagSet[$tagName]['block']) ? $tagSet[$tagName]['block'] : 1; $level = isset($tagSet[$tagName]['level']) ? $tagSet[$tagName]['level'] : 1; } for ($i = 0; $i < $level; $i++) { if (!$this->compileTag($tagName, $tagObj, $block)) { $i = 100; } } } } } private function compileTag($tagName, &$tagObj, $block = 1) { $arr = ''; if ($block) { $preg = '/' . $this->left . $tagName . "(?:\s+(.*)" . $this->right . "|" . $this->right . ")(.*)" . substr($this->left, 0, 1) . "\/" . substr($this->left, 1) . $tagName . $this->right . '/isU'; } else { $preg = '/' . $this->left . $tagName . '(?:\s+(.*)\/?' . $this->right . "|(\s*)\/?" . $this->right . ")/isU"; } $stat = preg_match_all($preg, $this->content, $arr, PREG_SET_ORDER); if (!$stat) { return false; } foreach ($arr as $k) { $k[1] = $this->replaceCondition($k[1]); $attr = $this->getTagAttr($k[1]); $k[2] = isset($k[2]) ? $k['2'] : ''; $content = call_user_func_array(array($tagObj, '_' . $tagName), array($attr, $k[2], $this->view)); $this->content = str_replace($k[0], $content, $this->content); } return true; } private function getTagAttr($attrCon) { $pregAttr = '/\s*' . '(\w+)\s*=\s*(["\'])(.*)\2/iU'; $attrs = ''; preg_match_all($pregAttr, $attrCon, $attrs, PREG_SET_ORDER); $attrArr = array(); foreach ($attrs as $k) { $k[3] = trim($this->parsePhpVar($k[3])); $attrArr[$k[1]] = strstr($k[3], '$') ? $k[3] : (is_numeric($k[3]) ? $k[3] : (defined($k[3]) ? $k[3] : $k[3])); } return array_change_key_case($attrArr); } private function parseVar($content) { $stripContent = stripslashes($content); $parseConstContent = $this->parseConst($stripContent); $content = $this->parsePhpVar($parseConstContent, 1); return $content; } private function replaceCondition($content) { foreach ($this->condition as $k => $v) { $content = preg_replace("/$k/", $v, $content); } return $content; } private function parsePhpVar($content, $type = 0) { $parseConstCon = $this->parseConst($content); $parseGlobalCon = $this->parseGlobalConst($parseConstCon); $replaceLangCon = $this->replaceLangConfig($parseGlobalCon); $content = $this->removeEmpty($replaceLangCon); if ($type == 0) { $preg = '/([\'\"]?)(\$[^=!<>\s\)\(]+)\1/is'; } else { $preg = '/([\'\"]?)(\$[^=!<>\)\(]+)\1/is'; } $vars = false; preg_match_all($preg, $content, $vars, PREG_SET_ORDER); if (empty($vars)) { return $content; } foreach ($vars as $v) { $v[2] = trim($v[2]); $content = str_replace($v[2], $this->formatVar($v[2]), $content); } return $content; } private function parseGlobalConst($content) { $preg = '/\$Hd.(get|post|request|cookie|session|server)\./ise'; $replace = '\'\$_\'.strtoupper("\1").".";'; return preg_replace($preg, $replace, $content); } private function removeEmpty($content) { $preg = array( '/[{}]/', '/\s*\|\s*/', '/\s*:\s*/', '/\s*,\s*/', ); $replace = array( '', '|', ':', ',', ); return preg_replace($preg, $replace, $content); } private function formatVar($var) { $varArr = preg_split("/\s*\|\s*/", $var); $varBase = array_shift($varArr); $func = $varArr; $preg = array( "/\.\'/", "/'\./", '/\."/', '/"\./', '/{/', '/}/', ); $replace = array( "/\./", "/\./", '/\./', '/\./', '/{/', '/}/', ); $con = preg_replace($preg, $replace, $varBase); $var = explode('.', $con); $varName = array_shift($var); $varStr = ''; if (count($var) > 0) { foreach ($var as $v) { $varStr .= is_numeric($v) || strstr($v, '$') ? "[{$v}]" : '[\'' . $v . '\']'; } } $varName .= str_replace("]'", "']", $varStr); if (!empty($func)) { if (!function_exists("replaceyinhao")) { function replaceyinhao($con) { return "'" . str_replace(":", "####", $con[2]) . "'"; } } foreach ($func as $function) { $function = preg_replace_callback('/(\'|")(.*)\1/i', "replaceyinhao", $function); $funcArr = explode(":", $function); $functionName = array_shift($funcArr); $funcName = array_key_exists($functionName, $this->functionAlias) ? $this->functionAlias[$functionName] : $functionName; if (isset($funcArr[0])) { if (strstr($funcArr[0], "@@")) { $varName = str_replace("@@", trim($varName, ','), $funcArr[0]); } else { $varName = trim($varName, ',') . ',' . $funcArr[0]; } } $varName = str_replace("####", ":", $varName); $varName = $funcName . '(' . trim($varName, ',') . '),'; } } return trim($varName, ','); } public function compile() { $preg = '/{(\$[^=!<>\)\(\+\;]+)}/ieU'; $this->content = preg_replace($preg, '\'<?php echo \'. $this->parseVar(\'\1\').\';?>\';', $this->content); } private function parseConst($content) { $preg = '/\$Hd[\.\[]([\'"])?const\1?[\.\]]([^=!<>\}]*)/is'; if (!function_exists("replace_view_const")) { function replace_view_const($args) { $name = strtoupper($args[2]); return defined($name) ? $name : $args[2]; } } return preg_replace_callback($preg, "replace_view_const", $content); } private function parseTokey() { if (!C("TOKEN_ON")) return; Token::create(); $preg = '/<\/form>/iUs'; $content = '<input type="hidden" name="<?php echo C("TOKEN_NAME");?>" value="<?php echo $_SESSION[C("TOKEN_NAME")]?>"/></form>'; $this->content = preg_replace($preg, $content, $this->content); } private function replaceConst() { $const = print_const(false, true); foreach ($const as $k => $v) { if (!strstr($k, '__')) continue; $this->content = str_replace($k, $v, $this->content); } } }final class Dir { static public function dirPath($dir_name) { $dirname = str_ireplace("\\", "/", $dir_name); return substr($dirname, "-1") == "/" ? $dirname : $dirname . "/"; } static public function getExt($file) { return strtolower(substr(strrchr($file, "."), 1)); } static public function tree($dirName = null, $exts = '', $son = 0, $list = array()) { if (is_null($dirName)) $dirName = '.'; $dirPath = self::dirPath($dirName); static $id = 0; if (is_array($exts)) $exts = implode("|", $exts); foreach (glob($dirPath . '*') as $v) { $id++; if (is_dir($v) || !$exts || preg_match("/\.($exts)/i", $v)) { $list [$id] ['name'] = basename($v); $list [$id] ['path'] = str_replace("\\", "/", realpath($v)); $list [$id] ['type'] = filetype($v); $list [$id] ['filemtime'] = filemtime($v); $list [$id] ['fileatime'] = fileatime($v); $list [$id] ['size'] = is_file($v) ? filesize($v) : self::get_dir_size($v); $list [$id] ['iswrite'] = is_writeable($v) ? 1 : 0; $list [$id] ['isread'] = is_readable($v) ? 1 : 0; } if ($son) { if (is_dir($v)) { $list = self::tree($v, $exts, $son = 1, $list); } } } return $list; } static public function get_dir_size($f) { $s = 0; foreach (glob($f . '/*') as $v) { $s += is_file($v) ? filesize($v) : self::get_dir_size($v); } return $s; } static public function treeDir($dirName = null, $son = 0, $pid = 0, $dirs = array()) { if (!$dirName) $dirName = '.'; static $id = 0; $dirPath = self::dirPath($dirName); foreach (glob($dirPath . "*") as $v) { if (is_dir($v)) { $id++; $dirs [$id] = array("id" => $id, 'pid' => $pid, "dirname" => basename($v), "dirpath" => $v); if ($son) { $dirs = self::treeDir($v, $son, $id, $dirs); } } } return $dirs; } static public function del($dirName) { if (is_file($dirName)) { unlink($dirName); return true; } $dirPath = self::dirPath($dirName); foreach (glob($dirPath . "*") as $v) { is_dir($v) ? self::del($v) : unlink($v); } return @rmdir($dirName); } static public function create($dirName, $auth = 0755) { $dirPath = self::dirPath($dirName); if (is_dir($dirPath)) return true; $dirs = explode('/', $dirPath); $dir = ''; foreach ($dirs as $v) { $dir .= $v . '/'; if (is_dir($dir)) continue; mkdir($dir, $auth); } return is_dir($dirPath); } static public function copy($olddir, $newdir, $strip_space = false) { $olddir = self::dirPath($olddir); $newdir = self::dirPath($newdir); if (!is_dir($olddir)) error("复制失败：" . $olddir . "目录不存在"); if (!is_dir($newdir)) self::create($newdir); foreach (glob($olddir . '*') as $v) { $to = $newdir . basename($v); if (is_file($to)) continue; if (is_dir($v)) { self::copy($v, $to, $strip_space); } else { if ($strip_space) { $data = file_get_contents($v); file_put_contents($to, strip_space($data)); } else { copy($v, $to); } chmod($to, "0777"); } } return true; } static public function safeFile($dirName, $recursive = false) { static $s = array(); $file = HDPHP_TPL_PATH . '/index.html'; if (!is_dir($dirName)) return; $dirPath = self::dirPath($dirName); is_file($dirPath . 'index.html') || copy($file, $dirPath . 'index.html'); foreach (glob($dirPath . "*") as $d) { if (is_dir($d) && !in_array($d, $s)) { $s[] = $d; is_file($d . '/index.html') || copy($file, $d . '/index.html'); $recursive && self::safeFile($d); } } } }C(array ( 'charset' => 'utf8', 'default_time_zone' => 'PRC', 'html_path' => 'h', 'debug_show' => true, 'language' => '', 'auth_key' => 'houdunwang', 'check_file_case' => 0, 'auto_load_file' => '', '404_tpl' => 'D:/wamp/www/v5/hdphp/hdphp/Lib/Tpl/404.html', 'db_driver' => 'mysqli', 'db_charset' => 'utf8', 'db_host' => '127.0.0.1', 'db_port' => 3306, 'db_user' => 'root', 'db_password' => '', 'db_database' => '', 'db_prefix' => '', 'db_backup' => 'D:/wamp/www/v5/backup/1387546090', 'token_on' => 0, 'token_name' => '__TOKEN__', 'debug_menu' => 1, 'show_system' => 1, 'show_cache' => 1, 'show_include' => 1, 'show_sql' => 1, 'show_tpl_compile' => 1, 'log_key' => 'houdunwang.com', 'log_size' => 2000000, 'log_type' => array ( ), 'session_auto' => 1, 'session_name' => 'hdsid', 'session_engine' => 'file', 'session_save_path' => '', 'session_lifetime' => 1440, 'session_table_name' => 'session', 'session_gc_divisor' => 10, 'session_memcache' => array ( 'host' => '127.0.0.1', 'port' => 11211, ), 'session_redis' => array ( 'host' => '127.0.0.1', 'port' => 6379, 'password' => '', 'db' => 0, ), 'https' => false, 'url_rewrite' => 0, 'url_type' => 1, 'pathinfo_dli' => '/', 'pathinfo_var' => 'q', 'pathinfo_html' => '', 'var_group' => 'g', 'var_app' => 'a', 'var_control' => 'c', 'var_method' => 'm', 'default_name' => '@', 'default_group' => 'App', 'default_app' => 'index', 'default_control' => 'Index', 'default_method' => 'index', 'control_fix' => 'Control', 'model_fix' => 'Model', 'filter_function' => array ( 0 => 'htmlspecialchars', 1 => 'strip_tags', ), 'route' => array ( ), 'cache_type' => 'file', 'cache_memcache' => array ( 'host' => '127.0.0.1', 'port' => 11211, 'timeout' => 1, 'weight' => 1, 'pconnect' => 1, ), 'cache_redis' => array ( 'host' => '127.0.0.1', 'port' => 6379, 'password' => '', 'timeout' => 1, 'db' => 0, 'pconnect' => 0, ), 'cache_time' => 3600, 'cache_select_time' => -1, 'cache_select_length' => 30, 'cache_tpl_time' => -1, 'upload_thumb_on' => 0, 'upload_ext_size' => array ( 'jpg' => 5000000, 'jpeg' => 5000000, 'gif' => 5000000, 'png' => 5000000, 'bmg' => 5000000, 'zip' => 5000000, 'txt' => 5000000, 'rar' => 5000000, 'doc' => 5000000, ), 'upload_path' => 'D:/wamp/www/v5//upload', 'upload_img_dir' => '', 'upload_img_resize_on' => 1, 'upload_img_max_width' => 1000, 'upload_img_max_height' => 1000, 'water_on' => 1, 'water_font' => 'D:/wamp/www/v5/hdphp/hdphp/Data/Font/font.ttf', 'water_img' => 'D:/wamp/www/v5/hdphp/hdphp/Data/Image/water.png', 'water_pos' => 9, 'water_pct' => 60, 'water_quality' => 80, 'water_text' => 'WWW.HOUDUNWANG.COM', 'water_text_color' => '#f00f00', 'water_text_size' => 12, 'thumb_prefix' => '', 'thumb_endfix' => '_thumb', 'thumb_type' => 6, 'thumb_width' => 300, 'thumb_height' => 300, 'thumb_path' => '', 'code_font' => 'D:/wamp/www/v5/hdphp/hdphp/Data/Font/font.ttf', 'code_str' => '123456789abcdefghijklmnpqrstuvwsyz', 'code_width' => 120, 'code_height' => 35, 'code_bg_color' => '#ffffff', 'code_len' => 4, 'code_font_size' => 20, 'code_font_color' => '', 'page_var' => 'page', 'page_row' => 10, 'page_show_row' => 10, 'page_style' => 2, 'page_desc' => array ( 'pre' => '上一页', 'next' => '下一页', 'first' => '首页', 'end' => '尾页', 'unit' => '条', ), 'tpl_engine' => 'HD', 'tpl_fix' => '.html', 'tpl_tag_left' => '<', 'tpl_tag_right' => '>', 'tpl_dir' => 'Tpl', 'tpl_tags' => array ( ), 'tpl_style' => '', 'tpl_compile' => 1, 'tpl_error' => 'error.html', 'tpl_success' => 'success.html', 'cart_name' => 'cart', 'editor_type' => 2, 'editor_style' => 1, 'editor_max_str' => 2000, 'editor_width' => '100%', 'editor_height' => 300, 'editor_file_size' => 2000000, 'rbac_type' => 1, 'rbac_super_admin' => 'super_admin', 'rbac_username_field' => 'username', 'rbac_password_field' => 'password', 'rbac_auth_key' => 'uid', 'rbac_no_auth' => array ( ), 'rbac_user_table' => 'user', 'rbac_role_table' => 'role', 'rbac_node_table' => 'node', 'rbac_role_user_table' => 'user_role', 'access_table' => 'access', 'email_username' => '', 'email_password' => '', 'email_host' => '', 'email_port' => 25, 'email_ssl' => 0, 'email_charset' => '', 'email_formmail' => '', 'email_fromname' => '后盾网', 'core_event' => array ( ), ));L(array ( 'functions_k_is_file' => '模型文件不存在', 'functions_k_error' => '模型类不存在', 'functions_control_error' => ' 控制器文件中没有定义类', 'functions_load_file_debug' => '文件不存在', 'functions_error_debug' => '查看详细错误信息方法有两种： ① 查看网站日志文件  ② 开启调试模式', 'control_error_msg' => '出错了', 'control_success_msg' => '操作成功', 'hd_mkdirs_path_temp' => '临时目录创建失败，请修改权限！', 'hd_mkdirs_path_log' => '日志目录创建失败，请修改权限！', 'hd_mkdirs_path_session' => 'SESSION目录目录创建失败，请修改权限！', 'mysql_insert_error' => '没有任何数据要插入,系统会将$_POST值自动插入，也可以手动将数据传入或者用ORM方式，请查看HD手册学习', 'mysql_insert_error2' => '插入数据错误，原因可能为1：插入内容为空   2：字段名非法，看一下HD框架手册吧！', 'mysql_update_error1' => '没有任何数据要更新,系统会将$_POST值自动更新，也可以手动将数据传入或者用ORM方式，请查看HD手册学习', 'mysql_where_error' => '的参数没有设置，如果不清楚使用方式请查看HD手册学习', 'mysql_in_error' => '的参数不能为空，如果不清楚使用方式请查看HD手册学习', 'mysql_field_error' => '的参数不能为空，如果不清楚使用方式请查看HD手册学习', 'model__call_error' => '模型中不存在方法', 'model_update_error' => '悲剧了。。。更新时，没有任何数据，系统也可以自动从$_POST中提取，如果还不清楚请参考HD框架手册', 'model_replace_error' => '悲剧了。。。INSERT参数不能为空！', 'model_token_error' => '表单Token(令牌)错误', 'relationmodel_check_error0' => '关联模型定义错误，请查看后盾HD框架手册学习', 'relationmodel_check_error1' => '多表操作定义的表的模型属性type值没有定义，如果不清楚使用规范，请参数HD框架帮助手册', 'relationmodel_check_error2' => '多表操作定义的表的模型属性type值必须是HAS_ONE、HAS_MANY、BELONGS_TO、MANY_TO_MANY中的一个，不区分大小写，如果不清楚使用规范，请参数HD框架帮助手册', 'relationmodel_check_error3' => '使用多表操作MANY_TO_MANY的表没有定义relation_table属性即中间关联表，如果不清楚使用规范，请参数HD框架帮助手册', 'relationmodel_check_error4' => '使用多表操作MANY_TO_MANY的表没有定义relation_table_parent_key属性，如果不清楚使用规范，请参数HD框架帮助手册', 'relationmodel_check_error5' => '使用多表操作MANY_TO_MANY的表没有定义relation_table_foreign_key属性，如果不清楚使用规范，请参数HD框架帮助手册', 'relationmodel_get_parent_key' => '表的主键不存在，手动设置主表的主键或都指定模型的parent_key值试试，还不行就看手册学习一下吧，很简单的！', 'relationmodel_get_foreign_key1' => 'MANY_TO_MANY关联失败：2种解决方法，设置关联表的主键或都指定模型的foreign_key值', 'relationmodel_get_foreign_key2' => '定义关联模型必须指定foreign_key值，如果不清楚使用规范，请参数HD框架帮助手册', 'relationmodel_select' => '模型的parent_key属性定义错误,可能不存在此字段,或者主表结果集中不含parent_key字段', 'relationmodel_insert' => '悲剧了。。。执行INSERT()时没有任何插入数据，插入数据可以是$_POST也可以直接传入INSERT()方法中，HD框架手册能帮到你！', 'relationmodel_update' => '悲剧了。。。执行INSERT()时没有任何插入数据，插入数据可以是$_POST也可以直接传入INSERT()方法中，HD框架手册能帮到你！', 'viewmodel_get_join_args1' => '定义视图必须指定ON值，如果不清楚使用规范，请参数HD框架帮助手册', 'viewmodel_get_join_args2' => '视图模型定义type值定义错误，type必须为left, right, inner之一。可以不设置type值,不设置将使用inner，如果不清楚使用规范，请参数HD框架帮助手册', 'view_gettemplatefile_error2' => '模版文件扩展名不能为空，请修改配置项TPL_FIX', 'view_gettemplatefile_error3' => '模版文件不存在', 'hdbasetag__zoom' => 'zoom标签必须设置 big、small、data属性，检查一下看哪个没有设置', 'hdbasetag__upload' => '上传标签upload必须指定name属性，如果不清楚使用规范请查看后盾HD框架手册', 'hdbasetag__foreach1' => 'foreach 模板标签必须有from属性', 'hdbasetag__foreach2' => 'foreach 模板标签必须有value属性', 'hdbasetag__load' => 'load 模板标签必须有value属性', 'hdbasetag__if' => 'if 模板标签必须有value属性', 'hdbasetag__while' => 'while模板标签必须有value属性', 'hdbasetag__empty' => 'empty模板标签必须有value属性', 'hdbasetag__editor' => '必须设置编辑器的name属性,用于$_POST接收', '_tag_param_error_' => '标签参数错误', 'tag_list_from_param_error' => 'list标签缺少from属性', 'tag_list_name_param_error' => 'list标签缺少name属性', 'debug_show1' => '服务器信息', 'debug_show2' => '客户端代理', 'debug_show3' => 'PHP版本', 'debug_show4' => '主机名', 'debug_show5' => '请求方式', 'debug_show6' => '通信协议', 'debug_show7' => '当前脚本', 'debug_show8' => '会话ID', 'debug_show9' => '模板编译文件', 'debug_show14' => '脚本总执行时间', 'debug_show15' => '内存峰值', '_nohavedebugstart' => '没有设置调试开始点：', 'exceptionhd_getexception1' => '错误信息', 'exceptionhd_getexception2' => '文件', 'exceptionhd_getexception3' => '行号', 'exceptionhd_show' => '查看详细错误信息方法有两种： ① 查看网站日志文件  ② 开启调试模式', 'exceptionhd_error1' => '错误信息', 'exceptionhd_error2' => '文件', 'exceptionhd_error3' => '行号', 'exceptionhd_error4' => '错误信息', 'exceptionhd_error5' => '文件', 'exceptionhd_error6' => '行号', 'exceptionhd_notice' => 'NOTICE', 'application_apprun1' => '控制器', 'application_apprun2' => '中的方法', 'application_apprun3' => '不存在', 'application_apprun4' => '应用不存在', 'application_apprun_createapp' => '点击创建应用', 'cart_add_error' => '购物车ADD方法参数设置错误', 'cart_update_error' => '购物车update方法参数错误，缺少sid或num值', 'cart_del_error' => '购物车update方法参数错误，缺少sid值', 'page_nowpage' => '第', 'page_count1' => '共', 'page_count2' => '页', 'page_count3' => '条记录', 'page_show_case1' => '总计', 'rbac_rbac_user_login1' => '用户表设置错误，请在配置文件中添加用户表', 'rbac_rbac_user_login2' => '用户不存在', 'rbac_rbac_user_login3' => '密码输入错误', 'rbac_rbac_user_login4' => '不属于任何组，没有访问权限', 'upload_upload_error' => '图片上传目录创建失败或不可写', 'upload_save_error1' => '图片上传目录创建失败或不可写', 'upload_save_error2' => '移动临时文件失败', 'upload_format_error' => '没有任何文件上传', 'upload_checkfile_error1' => '文件类型不允许', 'upload_checkfile_error2' => '上传文件大于', 'upload_checkfile_error3' => '非法文件', 'upload_checkfile_image' => '上传内容不是一个合法图片', 'upload_error_error1' => '上传文件超过PHP.INI配置文件允许的大小', 'upload_error_error2' => '文件超过表单限制大小', 'upload_error_error3' => '文件只上有部分上传', 'upload_error_error4' => '没有上传文件', 'upload_error_error5' => '没有上传临时文件夹', 'upload_error_error6' => '写入临时文件夹出错', 'validate__maxlen1' => '表单', 'validate__maxlen2' => '的值，必须为数字', 'validate__maxlen3' => '验证规则的maxlen参数设置错误，必须为数字', 'validate__minlen1' => '表单', 'validate__minlen2' => '的值必须为数字', 'validate__minlen3' => '验证规则的maxlen参数设置错误，必须为数字', 'success_html_title' => '后盾网提示——操作成功', 'success_html_hd_error_html_h2' => '操作成功!', 'success_html_span1' => '秒钟后将进行', 'success_html_span2' => '跳转', 'success_html_span3' => '也可以', 'success_html_span4' => '返回首页', 'error_html_title' => '后盾网提示——操作失败', 'error_html_hd_error_html_h2' => '操作失败!', 'error_html_span1' => '秒钟后将进行', 'error_html_span2' => '跳转', 'error_html_span3' => '也可以', 'error_html_span4' => '返回首页', '__call_method_no_exists' => '方法不存在', ));alias_import(array ( 'ip' => 'D:/wamp/www/v5/hdphp/hdphp/Extend/Org/Ip/Ip.class.php', 'mail' => 'D:/wamp/www/v5/hdphp/hdphp/Extend/Org/Mail/Mail.class.php', 'ueditor_upload' => 'D:/wamp/www/v5/hdphp/hdphp/Extend/Org/Editor/Ueditor/php/ueditor_upload.php', 'keditor_upload' => 'D:/wamp/www/v5/hdphp/hdphp/Extend/Org/Editor/Keditor/php/upload_json.php', 'hd_uploadify' => 'D:/wamp/www/v5/hdphp/hdphp/Extend/Org/Uploadify/hd_uploadify.php', 'hd_uploadify_del' => 'D:/wamp/www/v5/hdphp/hdphp/Extend/Org/Uploadify/hd_uploadify.php', 'editorcatcherurl' => 'D:/wamp/www/v5/hdphp/hdphp/Extend/Org/Editor/Ueditor/php/ueditorCatcherUrl.php', 'crop_image' => 'D:/wamp/www/v5/hdphp/hdphp/Extend/Org/crop_image/crop.php', ));HDPHP::init();define("CLEAR_TPL_COMPILE_FILE",strstr(__HOST__,$_SERVER["SERVER_NAME"])==false);App::run();?>